Clear datagrid values in wpf

后端 未结 7 1446
粉色の甜心
粉色の甜心 2021-01-11 19:14

I need to flush my datagrid everytime when a treeviewitem is clicked. My code is given below.

private void treeView1_SelectedItemCh         


        
7条回答
  •  执笔经年
    2021-01-11 20:04

    If you are populating the DataGrid by using:

    dataGrid.Items.Add(someObject);
    

    Then you should be able to use:

    dataGrid.Items.Clear(); 
    

    To remove all the rows.

    If you are binding to the ItemsSource like:

    dataGrid.ItemsSource = someCollection;
    

    Then you should be able to set the ItemsSource to null and it will remove all the rows.

    EDIT:

    Don't forget to refresh it:

    dataGrid.Items.Refresh();
    

提交回复
热议问题