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“中的值,