Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > obtain dataGridViewComboBoxColumn selectedItem
 

obtain dataGridViewComboBoxColumn selectedItem

OK. This combobox in datagridview is driving me batty. How does one grab the final selected item from the dataGridViewComboBoxColumn??

I saw one post where someone mentioned that you can do a cast to a editingcontrol and that would give you the selectedindex changed event. Any help is appreciated.

cheers

Boon

boondoggle  Thursday, January 11, 2007 11:55 AM

Private Sub dgv_EditingControlShowing(...) Handles dgv.EditingControlShowing

If e.Control.GetType() Is GetType(DataGridViewComboBoxEditingControl) Then

Dim cbo As ComboBox = e.Control

RemoveHandler cbo.SelectionChangeCommitted, AddressOf cboOnSelectionChangeCommitted

AddHandler cbo.SelectionChangeCommitted, AddressOf cboOnSelectionChangeCommitted

End If

End Sub

Private Sub cboOnSelectionChangeCommitted(ByVal sender As Object, ByVal e As EventArgs)

Dim cbo As ComboBox = CType(sender, ComboBox)

Console.WriteLine(cbo.SelectedValue.ToString())

End Sub

vkh75  Thursday, January 11, 2007 2:38 PM

Private Sub dgv_EditingControlShowing(...) Handles dgv.EditingControlShowing

If e.Control.GetType() Is GetType(DataGridViewComboBoxEditingControl) Then

Dim cbo As ComboBox = e.Control

RemoveHandler cbo.SelectionChangeCommitted, AddressOf cboOnSelectionChangeCommitted

AddHandler cbo.SelectionChangeCommitted, AddressOf cboOnSelectionChangeCommitted

End If

End Sub

Private Sub cboOnSelectionChangeCommitted(ByVal sender As Object, ByVal e As EventArgs)

Dim cbo As ComboBox = CType(sender, ComboBox)

Console.WriteLine(cbo.SelectedValue.ToString())

End Sub

vkh75  Thursday, January 11, 2007 2:38 PM

thanks a lot for helping me.

cheers

Boon

boondoggle  Sunday, January 14, 2007 7:44 PM
I am getting an error that i need to set cbo.SelectedValue.ToString() with New instance of
Ljhopkins  Wednesday, March 14, 2007 3:42 PM

You can use google to search for other answers

Custom Search

More Threads

• DataGridView ComboboxColumn error
• DataGridView rendering performance
• Backgroundworker filling dataset
• Writing a Database Utility
• Datagridview-Scrollbar
• change the column type of a column in the datagridview (vb2005) in runtime mode
• data records from oracle, insert
• Marking edited controls with a color
• Keeping controls in place when resizing a form
• Extract Currency Symbol