Datagridview ComboboxCell选中项变化时触发事件

private void Form1_Load(object sender, EventArgs e)
{
    List<string> list = new List<string>();
    list.Add("1");
    list.Add("2");
    list.Add("3");
    dgv_cb.DataSource = list;
}

// Save the row index
int RowIndex;

private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
    RowIndex = dataGridView1.CurrentCell.RowIndex;
    if (dataGridView1.CurrentCell.ColumnIndex == 0)
    {
        ComboBox comboBox = e.Control as ComboBox;
        comboBox.SelectedIndexChanged += new EventHandler(comboBox_SelectedIndexChanged);
    }
}

void comboBox_SelectedIndexChanged(object sender, EventArgs e)
{
    // Set the value of column "dgv_txt"
    dataGridView1.Rows[RowIndex].Cells[1].Value = ((ComboBox)sender).Text;
}

触发事件,修改”dgv-txt“中的值,

posted @ 2019-02-13 15:00  Kyle0418  阅读(1385)  评论(0编辑  收藏  举报