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 PatelPosted Dec 23, 2009, 9:33 PM
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)
{
}
AaronPosted Dec 28, 2009, 12:30 AM
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?
Kirtan PatelPosted Dec 28, 2009, 12:23 AM
ok try like this
ComboBox x = (ComboBox)sender;
if (combo != null)
{
MessageBox.Show(x.Name);
}
let me know what you get in msg box ..
AaronPosted Dec 28, 2009, 12:00 AM
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 PatelPosted Dec 27, 2009, 11:52 PM
In following Write Code to check which combo box is Accessed
void combo_SelectionChangeCommitted(object sender, EventArgs e)
{
}
AaronPosted Dec 27, 2009, 11:28 PM
Kirtan PatelPosted Dec 27, 2009, 10:08 PM
you can differentiate which combo box fired event
by
if(combo.Name == somthing)
{
// do somthing ;
}
else if(combo.Name == "another")
{
// do somthing ;
}
AaronPosted Dec 27, 2009, 9:33 PM