Datagrid View Dropdown list Event handler
I have added a dropdown column in DGridview but i am unable to generate event that shou开发者_Python百科ld fire when any value from dropdown menu is selected. Here is the code for adding column
DataGridViewComboBoxColumn com = new DataGridViewComboBoxColumn();
com.HeaderText = "";
com.Items.Add( "Print Invoice");
com.Items.Add("Print Job Card");
com.Items.Add("Close Job Card");
createCol = false;
ViewActiveJobs.Columns.Add(com);
Try this.You have to create new Event handler for Combobox and call that event in
EditingControlShowing .
private void ViewActiveJobs_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
comboBOX = (ComboBox)e.Control;
comboBOX .SelectedIndexChanged -=new EventHandler(comboBOX _SelectedIndexChanged);
comboBOX .SelectedIndexChanged +=new EventHandler(comboBOX _SelectedIndexChanged);
}
private void comboBOX _SelectedIndexChanged(object sender, EventArgs e)
{
ComboBox combo = sender as ComboBox;
string str=combo.SelectedIndex.ToString();
}
精彩评论