Hi,
i have a datagridview with datagridviewcombobox. How do i insert a event when user selects a value from the datagridviewcombobox? trying to bounddata for 2nd column of the datagridview based on what user selects from the datagridviewcombobox which is in the 1st column.
Loading

Kirtan PatelRank #292 · 8.6K reputationPosted Dec 23, 2009, 4:33 PM EST
Here is your Solution
please check "Do you like this answer" check box if it helps you :)
you need to build your Own Event Delegate to Handle this Combobox Changed Event in DataGridView as it Does not have that event
private DataGridView _dataGridView;
private EventHandler _comboBoxSelectDelegate;
public Example(){
}
void _dataGridView_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
}
void combo_SelectionChangeCommitted(object sender, EventArgs e)
{
}
Aaron13 reputationPosted Dec 27, 2009, 4:33 PM EST
Kirtan PatelRank #292 · 8.6K reputationPosted Dec 27, 2009, 5:08 PM EST
you can differentiate which combo box fired event
by
if(combo.Name == somthing)
{
// do somthing ;
}
else if(combo.Name == "another")
{
// do somthing ;
}
Aaron13 reputationPosted Dec 27, 2009, 6:28 PM EST
Kirtan PatelRank #292 · 8.6K reputationPosted Dec 27, 2009, 6:52 PM EST
In following Write Code to check which combo box is Accessed
void combo_SelectionChangeCommitted(object sender, EventArgs e)
{
}
Aaron13 reputationPosted Dec 27, 2009, 7:00 PM EST
private void comBoxEquipSelectionChange(object sender, EventArgs e)
{
ComboBox combo = sender as ComboBox;
if (combo != null)
{
MessageBox.Show(string.Format("The combobox selected index is: {0}", combo.SelectedIndex));
MessageBox.Show(combo.Name);
}
}
the popup is blank.
Kirtan PatelRank #292 · 8.6K reputationPosted Dec 27, 2009, 7:23 PM EST
ok try like this
ComboBox x = (ComboBox)sender;
if (combo != null)
{
MessageBox.Show(x.Name);
}
let me know what you get in msg box ..
Aaron13 reputationPosted Dec 27, 2009, 7:30 PM EST
here's how i declare my datagridview:
// gridEquipment (Datagridview)
//
this.gridEquipment.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
this.gridEquipment.ClipboardCopyMode = System.Windows.Forms.DataGridViewClipboardCopyMode.EnableWithoutHeaderText;
this.gridEquipment.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.gridEquipment.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.EquipmentTag,
this.Desc,
this.EquipmentCode,
this.EquipmentCodeDesc,
this.SpecCode,
this.ROQty,
this.UOM});
this.gridEquipment.Cursor = System.Windows.Forms.Cursors.Arrow;
this.gridEquipment.EditMode = System.Windows.Forms.DataGridViewEditMode.EditOnEnter;
this.gridEquipment.Enabled = false;
this.gridEquipment.ImeMode = System.Windows.Forms.ImeMode.Off;
this.gridEquipment.Location = new System.Drawing.Point(9, 177);
this.gridEquipment.MultiSelect = false;
this.gridEquipment.Name = "gridEquipment";
this.gridEquipment.ScrollBars = System.Windows.Forms.ScrollBars.None;
this.gridEquipment.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
this.gridEquipment.ShowEditingIcon = false;
this.gridEquipment.Size = new System.Drawing.Size(992, 331);
this.gridEquipment.TabIndex = 6;
this.gridEquipment.EditingControlShowing+= new System.Windows.Forms.DataGridViewEditingControlShowingEventHandler(gridEquip_EditingControlShowing);
//
// EquipmentTag (datagridviewcomboboxColumn)
//
this.EquipmentTag.AutoComplete = false;
this.EquipmentTag.DisplayStyle = System.Windows.Forms.DataGridViewComboBoxDisplayStyle.ComboBox;
this.EquipmentTag.HeaderText = "Equipment Tag";
this.EquipmentTag.Name = "EquipmentTag";
i binded a data from sql to EquipmentTag which has combo box.
the name EquipmentTag belongs to the column. but the combobox in the cell is not name. is there a way to name it?