Displaying hierarchal parent child data in WPF DataGrid

后端 未结 1 880
我寻月下人不归
我寻月下人不归 2020-12-19 16:51

I need to be able to display parent / child rows in a WPF datagrid, the parent are displayed with a plus / minus control which when clicked shows the related children record

相关标签:
1条回答
  • 2020-12-19 17:36

    Even i have the same requirement. I have implemented the condition in following way. When the expander is opened, you can have the following code.

    private void Expander_Expanded(object sender, RoutedEventArgs e)
    {
       foreach (var item in viewModel.Results)
       {
         if (item.SubResults.Count > 0)
          {
            item.SubResults.SelectedItem = null;
          }
       }
    }
    

    Where Results is the items source for my outer grid, and Subresults is the datasource for my inner grid. This code helps to reset the selected item, whenever the expander is opened.

    0 讨论(0)
提交回复
热议问题