简体   繁体   English

将数据网格值绑定到另一个数据网格

[英]Binding data grid values to another data grid

I have two datagrids. 我有两个数据网格。 The first contains the columns: 第一个包含以下列:

name, price, rank, rating, groupNumber ..... and many other columns

And the second contains: 第二个包含:

name, rating, groupNumber

Suppose I selected a row in the first datagrid and for that row GroupNumber was 6 , is there a way to display all the rows with groupNumer=6 using data binding in second datagrid? 假设我在第一个数据网格中选择了一行,并且该行的GroupNumber6 ,是否可以使用第二个数据网格中的数据绑定来显示所有groupNumer = 6的行?

What would be the best way to do such thing? 做这种事情的最好方法是什么?

Right now I doing it by selecting all the rows that have the same group number as the selected row in the first grid then copying those rows to another datatable then setting it as the source of the second grid. 现在,我通过选择与第一个网格中的选定行具有相同组号的所有行,然后将这些行复制到另一个数据表,然后将其设置为第二个网格的源来进行此操作。

Here is how i am doing it right now on row selection changed for the first grid: 这是我现在在第一个网格更改的行选择上的方式:

int gnum = //get the selected row gnum value
secondgrid.ItemsSource = firstgrid.Select(String.Format("gnum={0}", gnum)).CopyToDataTable().DefaultView;

您可以将相同的源绑定到两个DataGrid,但是在第二个中使用基于第一个DataGrid中当前行的过滤器

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

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