Datagrid View下拉列表事件处理程序

时间:2010-12-13 06:31:37

标签: c# winforms visual-studio-2010 datagridview

我在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);

1 个答案:

答案 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();

    }