DataGridView下拉框事件

private DataGridViewComboBoxEditingControl dataGridViewComboBox = null;

public event EventHandler ComboBoxCellChanged;

 

protected override void OnEditingControlShowing(DataGridViewEditingControlShowingEventArgs e)
{
    if (e.Control is DataGridViewComboBoxEditingControl && CurrentCell.RowIndex != -1)
    {
        this.dataGridViewComboBox = (DataGridViewComboBoxEditingControl)e.Control;
        //增加委托处理

        dataGridViewComboBox.SelectionChangeCommitted += new EventHandler(this.comboBox_SelectionChangeCommitted);
    }

    base.OnEditingControlShowing(e);
}

 

private void comboBox_SelectionChangeCommitted(object sender, EventArgs e)
{
    if (ComboBoxCellChanged != null)
        ComboBoxCellChanged(sender, e);
}

 

protected override void OnCellEndEdit(DataGridViewCellEventArgs e)
{
    if (this.dataGridViewComboBox != null)
    {
        dataGridViewComboBox.SelectionChangeCommitted -= new EventHandler(this.comboBox_SelectionChangeCommitted);
        this.dataGridViewComboBox = null;
    }
    base.OnCellEndEdit(e);
}

posted @ 2010-02-25 15:44  cindymeng  阅读(354)  评论(0编辑  收藏  举报