G
Guest
In the documentation, I see an example of how to capture the
SelectedIndexChange of a DataGridViewComboBox. Does anyone know how to
identify which combobox you've got on EditControlShowing if you have more
than one? stupid or otherwise, I tried e.control.name (and some others) with
no luck
Here's what the docs say
Private WithEvents dataGridView1 As New DataGridView()
Private Sub AddColorColumn()
Dim comboBoxColumn As New DataGridViewComboBoxColumn()
comboBoxColumn.Items.AddRange( _
Color.Red, Color.Yellow, Color.Green, Color.Blue)
comboBoxColumn.ValueType = GetType(Color)
dataGridView1.Columns.Add(comboBoxColumn)
End Sub
Private Sub dataGridView1_EditingControlShowing(ByVal sender As Object, _
ByVal e As DataGridViewEditingControlShowingEventArgs) _
Handles dataGridView1.EditingControlShowing
Dim comboBox1 As ComboBox = CType(e.Control, ComboBox)
AddHandler comboBox1.SelectedIndexChanged, _
New EventHandler(AddressOf ComboBox_SelectedIndexChanged)
End Sub
Private Sub ComboBox_SelectedIndexChanged( _
ByVal sender As Object, ByVal e As EventArgs)
Dim comboBox1 As ComboBox = CType(sender, ComboBox)
comboBox1.BackColor = _
CType(CType(sender, ComboBox).SelectedItem, Color)
End Sub
SelectedIndexChange of a DataGridViewComboBox. Does anyone know how to
identify which combobox you've got on EditControlShowing if you have more
than one? stupid or otherwise, I tried e.control.name (and some others) with
no luck
Here's what the docs say
Private WithEvents dataGridView1 As New DataGridView()
Private Sub AddColorColumn()
Dim comboBoxColumn As New DataGridViewComboBoxColumn()
comboBoxColumn.Items.AddRange( _
Color.Red, Color.Yellow, Color.Green, Color.Blue)
comboBoxColumn.ValueType = GetType(Color)
dataGridView1.Columns.Add(comboBoxColumn)
End Sub
Private Sub dataGridView1_EditingControlShowing(ByVal sender As Object, _
ByVal e As DataGridViewEditingControlShowingEventArgs) _
Handles dataGridView1.EditingControlShowing
Dim comboBox1 As ComboBox = CType(e.Control, ComboBox)
AddHandler comboBox1.SelectedIndexChanged, _
New EventHandler(AddressOf ComboBox_SelectedIndexChanged)
End Sub
Private Sub ComboBox_SelectedIndexChanged( _
ByVal sender As Object, ByVal e As EventArgs)
Dim comboBox1 As ComboBox = CType(sender, ComboBox)
comboBox1.BackColor = _
CType(CType(sender, ComboBox).SelectedItem, Color)
End Sub