Click here to Skip to main content
15,890,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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,
VB
ds = dataset
DgvBs + DgvBs1 = Binding Source

DgvBs.DataSource = ds
DgvBs.DataMember = "tbl_class_attrib" 'Parent Table

DgvBs1.DataSource = DgvBs
DgvBs1.DataMember = "data_relation" 'data_relation with child table

DataGridView1.DataSource = DgvBs

Then i made a DataGridviewMultiColumnComboboxColumn to datagridview1
VB
Dim newMColumn As New DataGridViewMultiColumnComboBoxColumn
newMColumn.CellTemplate = New DataGridViewMultiColumnComboBoxCell()
'newMColumn.DisplayStyle = DataGridViewComboBoxDisplayStyle.ComboBox
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:

VB
Private Sub DataGridView1_EditingControlShowing(sender As Object, e As DataGridViewEditingControlShowingEventArgs) Handles DataGridView1.EditingControlShowing
	'Dim colIndex As Integer = Me.DataGridView1.CurrentCell.ColumnIndex
	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
Posted
Updated 28-Mar-17 0:33am
v4
Comments
CHill60 27-Mar-17 7:30am    
Did you post this question on the forum at the bottom of the article?
Member 10058701 27-Mar-17 8:37am    
No, i didn't.
the post on that forum is in c# and 2 years old, i have converted it and then implemented at my own,
and and this problem is occurring in all kind of ComboboxColumn, even it is in datagridview default ComboboxColumn.
CHill60 27-Mar-17 8:48am    
Fair enough - it's good that other members can see this comment and understand how much work you have put into this. I'll have another look
Member 10058701 27-Mar-17 9:01am    
Thanks, i am waiting of your reply
Member 10058701 28-Mar-17 2:42am    
Is anybody here can help ???

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900