![](/img/trans.png)
[英]How do I bind row count of a datagrid to a textblock text whose specific column has specific values?
[英]How do I pass values from a specific row on a DataGrid as a parameter?
我有一个DataGridView,我希望将特定行上的所有值都传递给新表单。 我知道如何提取值,但是如何将这些值传递到新表单中(每个值都将分配给特定的文本框)?
您是否要从新表单中隐藏其余的DataGridView? 例如,如果将DataGridViewRow传递给表单,则新表单可以直接获取值。 但这也将使他们能够访问DataGridView。
DataGridViewRow dgr = dataGridView.Rows[0];
MyForm myForm = new MyForm(dgr); // now the form has the Row of information. But it can also access the entire DataGridView as it is available in the DataGridViewRow.
如果要删除对DataGridView的访问权限,则将行中的值放入容器中并传递该容器。 您可以使用内置的东西,例如ArrayList,List等。或创建自己的自定义容器。
我将创建一个类,该类具有数据集中每个列的属性。 然后,您可以使用班级列表来存储所有内容,并且列表中的每个元素都是一行。 然后,您可以设置DataGridView.DataSource = yourList
。 当您需要传递一列时,只需传递列表中的那个元素即可。
如果确实不需要为数据创建类,则还可以将DataGridViewRow传递给函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.