如何基于对另一个WPF数据网格的选择来填充一个WPF数据网格 [英] How to fill one WPF Datagrid based on selection of another datagrid

查看:106
本文介绍了如何基于对另一个WPF数据网格的选择来填充一个WPF数据网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有两个数据网格,其列分别为CheckBoxColumn1,TextColumn1,TextColumn2

从第一数据网格中选择行时,我的第二数据网格内容应使用相同的ID填充,但与数据库的详细信息不同.

Hi,

I have two datagrids with columns as CheckBoxColumn1 ,TextColumn1, TextColumn2

On selection of row from 1st datagrid , my 2nd Datagrid content should fill with same ID but different details from database.

How can i do so??

推荐答案

监视所选项目(使用绑定事件触发器 ).更改后,请使用新项从数据库中获取所需的信息,然后重新填充第二个数据网格的源集合.




XAML
Monitor the selected item (either with binding or an event trigger). When it changes use the new item to fetch the needed info from your data base and then re-populate the source collection for the second data grid.




XAML
<datagrid>
  SelectedValue="{Binding Path=SelectedValue}"
  ItemSource="{Binding Path=Source1}"
/>
<datagrid>
  ItemSource="{Binding Path=Source2}"
/>
</datagrid></datagrid>



数据上下文



DATA CONTEXT

        public ObservableCollection<data> Source1 { get; private set; }

        public ObservableCollection<data> Source2 { get; private set; }

        public Data SelectedValue
        {
            get { return _selectedValue; }
            set
            {
                if (_selectedValue == value) return;
                _selectedValue = value;
                PopulateSource2();
            }
        }

        private void PopulateSource2()
        {
            Source2.Clear();
            //Get your other data from DB here

            Source2.Add(SelectedValue);//This is just to show that it works
        }
</data></data>


这篇关于如何基于对另一个WPF数据网格的选择来填充一个WPF数据网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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