0

我正在尝试创建一个输出简单文本文件的应用程序。这是我在 C# 中的第一个项目。我创建了一个数据网格表。每行基本上有5个单元格,并且在用户输入后动态添加行。用户只能更改 5 个单元格中的 2 个单元格中的值。我的问题出在这里,在第三个单元格中,用户必须从单元格 3 的组合框中选择一个值,单元格 4 和 5 中的值将在选择组合框中的值后填充。但是我无法做到这一点。附上图片供参考。应用图像

4

1 回答 1

2

你可以尝试这样的事情:

//EditingControlShowing event handler for your dataGridView1
private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e){
   ComboBox combo = e.Control as ComboBox;
   if(combo != null) combo.SelectedIndexChanged += GridComboSelectedIndexChanged;
}
private void GridComboSelectedIndexChanged(object sender, EventArgs e) {
   ComboBox combo = sender as ComboBox;
   //Your populating code here
   //you can access the selected index via combo.SelectedIndex
   //you can access the current row by dataGridView1.CurrentCell.OwningRow
   //then you can access to the cell 4 and cell 5 by dataGridView.CurrentCell.OwningRow.Cells[4] and dataGridView.CurrentCell.OwningRow.Cells[5]
}
于 2013-08-11T00:20:44.480 回答