I dynamically create columns in my datagridview
The columns that are ComboBox have items added to them when they are being created.
Most of these items are strings, but one column has numbers added.
I then bind the datagridview to a datatable.
When the datagrid is displayed the comboboxes that have associated with strings display the datatable value
the combobox that is associalted with numbers (singles) displays the first item in the list.
Any suggestions?
Code:
Sub AddComboColumn(ThisView As DataGridView, ByVal MyList(,) As String, icol As Integer, sName As String, oType As Type, iWidth As Integer)
Dim cmbcol As DataGridViewComboBoxColumn
cmbcol = New DataGridViewComboBoxColumn()
cmbcol.HeaderText = sName
cmbcol.Name = sName
cmbcol.DataPropertyName = sName
cmbcol.DisplayMember = cmbcol.DataSource
cmbcol.ValueType = oType
cmbcol.ReadOnly = False
cmbcol.Width = iWidth
Dim ir As Integer
For ir = 0 To UBound(MyList, 2) ' MyList.Count - 1
If MyList(icol, ir) = "" Then Exit For
If oType = GetType(Single) Then
cmbcol.Items.Add(Math.Round(Val(MyList(icol, ir)), 2))
Else
cmbcol.Items.Add(MyList(icol, ir))
End If
Next ir
ThisView.Columns.Add(cmbcol)
End Sub
Code:
Dim PBBindingSource As New BindingSource
Dim ThisDataView As New DataView
ThisDataView = New DataView(rs)
ThisDataView.RowFilter = ""
ThisDataView.Sort = ""
PBBindingSource.DataSource = ThisDataView.ToTable(True, msShowField)
PBBindingSource.Filter = ""
PBBindingSource.Sort = ""
dgConfiguration.DataSource = PBBindingSource
dgConfiguration.Refresh()