我在DGridview中添加了一个下拉列,但是当我选择了下拉菜单中的任何值时,我无法生成应该触发的事件。 以下是添加列
的代码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);
答案 0 :(得分:1)
试试这个。你必须为Combobox创建新的事件处理程序并在
中调用该事件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();
}