每次點擊treeviewitem
時,需要刷新我的datagrid
。我的代碼如下。清除wpf中的datagrid值
private void treeView1_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
{
this.dataGrid1.Columns.Clear();
this.dataGrid1.ItemsSource= null;
String path =this.treeView1.SelectedItem;
if (!File.Exists(path))
MessageBox.Show("Not Found");
else
{
ob.provider(path);
// String data = @"C:\logs.xml";
string data = path;
objref.functionality(data);
this.dataGrid1.ItemsSource = objref.Result;
}
}
但每次當我點擊一個treeview項時,datagrid沒有被清除 - 它附加了傳入數據。 我用dataGrid1.Columns.Clear()
和dataGrid.ItemSource= null;
我該怎麼做?
上午填充。我已經將它設置爲空。這是我的問題。但我的數據網格仍然沒有清除。 – BinaryMee
這是你填充它的唯一位置嗎? – Rhexis
嘗試刷新它:dataGrid.Items.Refresh(); – Rhexis