comboboxcolumn in datagridview

N

noob

Hi
I am having issues with a combobox column in a datagridview with virtual
mode enabled. I am binding data to both the datagrid and combobox from
an sql database. Everything works fine however when I select an item in
the combobox and move onto the next row, the item dissapears from the
combobox and it moves back to a blank state. I have put a break point
at: (and it fires off when I click the drop down on the combobox). Can
anyone suggest a solution.

Private Sub DataGridView1_EditingControlShowing(ByVal sender As
System.Object, ByVal e As DataGridViewEditingControlShowingEventArgs)
Handles DataGridView1.EditingControlShowing

Dim editingComboBox As ComboBox = CType(e.Control, ComboBox)
AddHandler editingComboBox.SelectedIndexChanged, AddressOf
Me.editingComboBox_SelectedIndexChanged

End Sub
 
J

Jim Wooley

Hi
I am having issues with a combobox column in a datagridview with
virtual
mode enabled. I am binding data to both the datagrid and combobox from
an sql database. Everything works fine however when I select an item
in
the combobox and move onto the next row, the item dissapears from the
combobox and it moves back to a blank state. I have put a break point
at: (and it fires off when I click the drop down on the combobox). Can
anyone suggest a solution.
Private Sub DataGridView1_EditingControlShowing(ByVal sender As
System.Object, ByVal e As DataGridViewEditingControlShowingEventArgs)
Handles DataGridView1.EditingControlShowing

Dim editingComboBox As ComboBox = CType(e.Control, ComboBox)
AddHandler editingComboBox.SelectedIndexChanged, AddressOf
Me.editingComboBox_SelectedIndexChanged
End Sub

Where do you remove the handler for the combobox. I suspect that you are
adding another handler when you move to the next row and not removing the
handler from the last row, thus both are now handling the same event. Since
the new row is cleared, it is telling the old row to clear itself. In my
case, I have just used the native DataGridViewComboBoxColumn and let the
standard binding take control. This means that my object is not updated until
the cell changes focus, but I have resigned myself to that situation at this
point.

FWIW, I did run into a problem with disposing the form when the combo box's
datasource was still bound. I put a solution up at http://devauthority.com/blogs/jwooley/archive/2005/12/02/638.aspx.

Jim Wooley
http://devauthority.com/blogs/jwooley/default.asp
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top