Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27554

VS 2010 bound and unbound columns in datagridview

$
0
0
I use a bounded datagridview (I bind it by code)
I want to add a column, which is a description of a code in a column in the datagridview:
for instance, i have a column of org_unit_id, and i want to bring the description of that org_unit_id from another table into unbounded column (and not to create that column in the base table for the datagridview)

Can anyone give me an example?

This is the procedure I use to populate the datagridview:
Code:

      Try
            dgvBgtManagement.AutoGenerateColumns = False
            dgvBgtManagement.DataSource = dvDataView
            dgvBgtManagement.ColumnHeadersDefaultCellStyle.Font = New System.Drawing.Font("Arial", 15.0F, _
            System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, _
            Convert.ToByte(0))
            Dim clOrgUnitId As New DataGridViewTextBoxColumn
            clOrgUnitId = BuildDGVTextBoxCulumn(clOrgUnitId, "org_unit_id", _
            "clOrgUnitId", 70, "", False, "#0", Me.Name, dgvBgtManagement)
            Dim clItemId As New DataGridViewTextBoxColumn
            clItemId = BuildDGVTextBoxCulumn(clItemId, "item_id", "clItemId", 70, "", _
            False, "#0", Me.Name, dgvBgtManagement)
            Dim clItemIdDesc As New DataGridViewTextBoxColumn
            clItemId = BuildDGVTextBoxCulumn(clItemIdDesc, "item_desc", "clItemIdDesc", 70, "", _
            False, "#", Me.Name, dgvBgtManagement)
        Catch ex As Exception
            HandleExceptions(ex)
        End Try
    End Sub

Function BuildDGVTextBoxCulumn(ByVal clColumn As DataGridViewTextBoxColumn,
                                  ByVal stDataPropertyName As String, _
                                  ByVal stHeader As String, _
                                  ByVal dWidth As Double, _
                                  ByVal stNullText As String, _
                                  ByVal blnReadOnly As Boolean, _
                                  ByVal stFormat As String, _
                                  ByVal stFormName As String, _
                                  ByVal dgvDataGridView As DataGridView) As DataGridViewTextBoxColumn
        Try
            With clColumn
                .DataPropertyName = stDataPropertyName
                .HeaderText = stHeader
                .Width = dWidth * dWidthChange
                .DefaultCellStyle.NullValue = stNullText
                .ReadOnly = blnReadOnly
                .DefaultCellStyle.Format = stFormat
                If blnReadOnly = True Then
                    '      .TextBox.BackColor = System.Drawing.Color.White
                End If
            End With
            dgvDataGridView.Columns.Add(clColumn)
            Return clColumn
        Catch ex As Exception
            HandleExceptions(ex)
            Return clColumn
        End Try
    End Function


Viewing all articles
Browse latest Browse all 27554

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>