0

我在 DataGridViewComboBoxCell 中有一个项目列表;我想在用户单击一个值后立即做某事。

事件是什么,或者我怎么能做我想做的事?

当我们离开单元格时调用 CellValueChanged...

4

2 回答 2

2

您可以处理组合框的 selectededindexchanged 。

private void dataGridView1_EditingControlShowing(object sender, 
                    DataGridViewEditingControlShowingEventArgs e)
{
    ComboBox cb = e.Control as ComboBox;
    if (cb != null)
    {
        // first remove event handler to keep from attaching multiple:
        cb.SelectedIndexChanged -= new
        EventHandler(cb_SelectedIndexChanged);

        // now attach the event handler
        cb.SelectedIndexChanged += new 
        EventHandler(cb_SelectedIndexChanged);
    }
}

void cb_SelectedIndexChanged(object sender, EventArgs e)
{
    MessageBox.Show("Selected index changed");
}
于 2012-11-01T19:19:34.950 回答
0

另一种可能的方法是:

private void dataGridView1_EditingControlShowing(object sender,  
                                                 DataGridViewEditingControlShowingEventArgs e)
{
    ComboBox cb = e.Control as ComboBox;
    if (cb == null)
        return;

    dataGridView1.EditingControlShowing -= dataGridView1_EditingControlShowing;
    cb.SelectedIndexChanged += cb_SelectedIndexChanged;
}

void cb_SelectedIndexChanged(object sender, EventArgs e)
{
    MessageBox.Show("Selected index changed");
}

你只做一次。

于 2012-11-02T05:47:30.357 回答