Hi Experts,
I have implemented "Multi Column ComboboxColumn" inside databind datagridview,
Implemented from this link (
Multi-Column Combo Box in a DataGridView[
^] But Facing One Problem, when i bind the ComboboxColumn to data table, every thing ok,
but when i bind it to data_relation , it shows all data, after selection done,
values disappears on losing focus,
1- if i have open a new form before close this form, this column selected values disappears,
2- or if move this form or scroll datagridview its values disappear just focused values show.
i have tried every thing and searched alot But still cannot solve the problem.
My Dataset has two data tables and one data_relation on both tables,
tbl_class_attrib 'Parent Table
tbl_class_attrib_values 'ChildTable
i have successfully populated dataset, made data_relation on both tables, and bind with Binding source like this,
ds = dataset
DgvBs + DgvBs1 = Binding Source
DgvBs.DataSource = ds
DgvBs.DataMember = "tbl_class_attrib"
DgvBs1.DataSource = DgvBs
DgvBs1.DataMember = "data_relation"
DataGridView1.DataSource = DgvBs
Then i made a
DataGridviewMultiColumnComboboxColumn
to
datagridview1
Dim newMColumn As New DataGridViewMultiColumnComboBoxColumn
newMColumn.CellTemplate = New DataGridViewMultiColumnComboBoxCell()
newMColumn.FlatStyle = FlatStyle.Flat
newMColumn.HeaderText = "attrib_value_code"
newMColumn.Name = "attrib_value_code"
newMColumn.DataPropertyName = "attrib_value_name"
newMColumn.DisplayMember = "attrib_value_name"
newMColumn.ValueMember = "attrib_value_code"
newMColumn.DataSource = DgvBs1
DataGridView1.Columns.Add(newMColumn)
DgvBs1 is 2nd binding source
CAN ANY ONE HELP ,
Thanks
What I have tried:
Private Sub DataGridView1_EditingControlShowing(sender As Object, e As DataGridViewEditingControlShowingEventArgs) Handles DataGridView1.EditingControlShowing
Dim cb As System.Windows.Forms.ComboBox = TryCast(e.Control, System.Windows.Forms.ComboBox)
If DataGridView1.CurrentCell.IsComboBoxCell Then
If DataGridView1.Columns(DataGridView1.CurrentCell.ColumnIndex).Name = "attrib_value_code" Then
If cb IsNot Nothing Then
RemoveHandler cb.SelectionChangeCommitted, AddressOf ComboBox1_SelectionChangeCommitted
AddHandler cb.SelectionChangeCommitted, AddressOf ComboBox1_SelectionChangeCommitted
End If
End If
End If
End Sub
Private Sub ComboBox1_SelectionChangeCommitted(sender As Object, e As EventArgs)
If DgvBs1.Current IsNot Nothing Then
Dim Index As Int32 = DgvBs1.Find("attrib_value_name", TryCast(sender, DataGridViewMultiColumnComboBoxEditingControl).Text)
If Index <> -1 Then
DgvBs1.Position = Index
DataGridView1.CurrentRow.Cells(DataGridView1.Columns("TxtBoxColumn").Index).Value = CType(DgvBs1.Current, DataRowView).Row.Field(Of String)("attrib_value_name")
DataGridView1.CurrentRow.Cells(DataGridView1.Columns("attrib_value_code").Index).Value = CType(DgvBs1.Current, DataRowView).Row.Field(Of String)("attrib_value_name")
End If
End If
End Sub