DataGridView ComboBox

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
 
T

Tim Van Wassenhove

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


int columnIndex = dataGridView1.CurrentCell.ColumIndex;


(PS: Notice that everytime the editingcontrol event raises, you'll add
another eventhandler to the combobox...)
 
G

Guest

Thanks Tim

Tim Van Wassenhove said:
int columnIndex = dataGridView1.CurrentCell.ColumIndex;


(PS: Notice that everytime the editingcontrol event raises, you'll add
another eventhandler to the combobox...)
 

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