C# .NET - DataGridViewComboBoxColumn selection chenge

Asked By Jipin M on 10-Nov-11 05:38 AM
Hi all.......

I add a DataGridViewComboBoxColumn and DataGridViewTextBoxColumn
in a DataGridview control.

How to add an event for selection change in DataGridViewComboBoxColumn and Change the value in DataGridViewTextBoxColumn for each selection changed.
Regards..............
Kirtan Patel replied to Jipin M on 10-Nov-11 05:43 AM
private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
  //This is private variable ComBoBox.
  if (combo == null)
  {
    combo = (ComboBox)e.Control;
    combo.SelectedIndexChanged += new EventHandler(combo_SelectedIndexChanged);
  }
}
private void combo_SelectedIndexChanged(object sender, EventArgs e)
{
  MessageBox.Show("Coming");
}
 
dipa ahuja replied to Jipin M on 10-Nov-11 05:44 AM
private void dataGridView1_EditingControlShowing(object sender,
DataGridViewEditingControlShowingEventArgs e)
{
if (dataGridView1.CurrentCell.ColumnIndex == 0)
{
// Check box column
ComboBox comboBox = e.Control as ComboBox;
comboBox.SelectedIndexChanged += new EventHandler(comboBox_SelectedIndexChanged);
}
}
 
void comboBox_SelectedIndexChanged(object sender, EventArgs e)
{
int selectedIndex = ((ComboBox)sender).SelectedIndex;
MessageBox.Show("Selected Index = " + selectedIndex);
} http://generally.wordpress.com/2007/12/07/datagridview-get-selectedindex-of-datagridviewcomboboxcolumn/