DataGridViewComboBox:根据同一行中另一列的值,为详细网格中的每一行填充不同的数据 [英] DataGridViewComboBox: populate with different data for each row in detail grid based on another column's value in the same row

查看:90
本文介绍了DataGridViewComboBox:根据同一行中另一列的值,为详细网格中的每一行填充不同的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。我的 WinForms应用程序中有一对Master-Detail DataGridViews。

我的 DETAIL 网格中的一列是ComboBox(part_name) 。



ComboBox值对于所有行都不相同。它们根据 DETAIL 网格的同一行中另一列(设备名称)的值而不同。

示例:



row1:equipment_name:PC part_name:RAM,硬盘,CPU

row2:equipment_name:printer part_name:纸盒,Inkwell



当详细行从数据库填充或由用户添加时,如何在每个 DETAIL 行中使用正确的值填充每个ComboBox?也许使用数据库查询?如何将(equipment_name)作为参数传递?在哪里这样做?在什么事件处理程序?





PS

1- master和细节网格用于显示,添加,编辑和删除行。

2-在此页面中,您可以找到我创建网格的代码。它还没有包含ComboBox列的代码。 正确的代码标记为ANSWER



www.codeproject.com/Questions/817587/Master-detail-datagridview-how-to-insert-master- re?arn = 0& loginkey = false [ ^ ]



提前感谢

Hi. I have a pair of Master-Detail DataGridViews in my WinForms App.
One of the columns in my DETAIL grid is a ComboBox (part_name).

ComboBox values are not the same for all rows. They differ based on the value of another column (equipment_name) in the same row of the DETAIL grid.
example:

row1: equipment_name: PC part_name: RAM , Hard disc , CPU
row2: equipment_name: printer part_name: paper tray , Inkwell

How can i populate each ComboBox with correct values in each DETAIL row when detail rows are either filled from database or added by user? maybe using a database query? how to pass(equipment_name) as a parameter? and where to do that? in what event handler?


P.S. :
1- master and detail grids are used for displaying, adding , editing and deleting rows.
2- in this page you can find my code of creating grids. it doesn't include code for ComboBox column yet. the correct code is marked as an ANSWER.

www.codeproject.com/Questions/817587/Master-detail-datagridview-how-to-insert-master-re?arn=0&loginkey=false[^]

thanks in advance

推荐答案

使用CellFormatting事件检查设备名称并根据组合框列的设置数据源。



您也可以使用DataBindingComplete,但你必须遍历整个网格并重新绑定你的组合框值,这不是理想的。



在CellFormatting中,检查单元格索引或单元格列名,如果它是您的设备名称,请将您的数据源绑定到combob牛栏
Use CellFormatting event to check for equipment name and based on that set datasource for the combobox column.

You can also use DataBindingComplete, but you have to then iterate through whole grid and re-bind your combobox values which is less than ideal.

In CellFormatting, check cell index or cellcolumn name, if it is your equipment name, bind your datasource to combobox column


这篇关于DataGridViewComboBox:根据同一行中另一列的值,为详细网格中的每一行填充不同的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆