How to Detect ComboBox Selected Value in DataGridView

Submitted by: 
Visitors have accessed this post 3173 times.

Detecting the selected value of ComboBox is done by using the event like SelectedIndexChanged, SelectedValueChanged, and SelectionChangeCommitted. This event is being fired once you select a value in a ComboBox.

However, if you have a ComboBox column in DataGridView control, you cannot easily use those events without adding a Handler. So, in this case, you need to create a procedure that will listen as an event to a handler that you have created.

Here’s an example code on how to detect the selected value of a ComboBox column in DataGridView control.

  1. Private Sub ProductDetailDataGridView_EditingControlShowing(sender As Object, e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles ProductDetailDataGridView.EditingControlShowing
  2. Dim combo As ComboBox = TryCast(e.Control, ComboBox)
  4. If combo IsNot Nothing Then
  5. RemoveHandler combo.SelectionChangeCommitted, AddressOf ComboBox_SelectionChangeCommitted
  6. AddHandler combo.SelectionChangeCommitted, AddressOf ComboBox_SelectionChangeCommitted
  7. End If
  8. End Sub
  10. Private Sub ComboBox_SelectionChangeCommitted(sender As Object, e As EventArgs)
  11. Dim cb As ComboBox = DirectCast(sender, ComboBox)
  12. Dim strValue As String = cb.Text
  14. If strValue IsNot Nothing Then
  15. MessageBox.Show(strValue)
  16. End If
  17. End Sub

In the example above, we created a procedure called ComboBox_SelectionChangeCommitted. This event is being fired once you select a value in ComboBox inside a DataGridView control. This procedure listens to an event after you declare a new handler AddHandler combo.SelectionChangeCommitted, AddressOf ComboBox_SelectionChangeCommitted

I used the SelectionChangeCommitted to prevent the event from firing when you select another row in DataGridView control.


Can you send me the code for log in for different users such as client, admin, and client.

this is my email :

[email protected]

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.