繁体   English   中英

选择组合框的值后,在datagrid单元格中添加值c#

[英]Add value in datagrid cell after value of combobox is selected c#

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

你可以尝试这样的事情:

//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]
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM