简体   繁体   English

清除wpf中的datagrid Itemssource

[英]clearing datagrid Itemssource in wpf

I'm using a datagrid in my program,and bind it with Itemssource.我在我的程序中使用了一个数据网格,并将它与 Itemssource 绑定。 I wanna clear all rows programmatically ,not one by one and I wanna save my Itemssource so I can't use datagrid.Itemssource=null;我想以编程方式清除所有行,而不是一一清除,我想保存我的 Itemssource 所以我不能使用 datagrid.Itemssource=null; because I can't use datagrid with that Itemssource again, and I dont want to make a new Itemssource each time,in fact,I have to clear my Itemssource programmatically.因为我不能再次将 datagrid 与那个 Itemssource 一起使用,而且我不想每次都创建一个新的 Itemssource,事实上,我必须以编程方式清除我的 Itemssource。 now,any idea to clear rows??现在,有清除行的想法吗? thx谢谢

if you have a ObservableCollection bind to your DataGrid ItemsSource simply use .Clear()如果你有一个 ObservableCollection 绑定到你的 DataGrid ItemsSource 只需使用 .Clear()

public OberservableCollection<MyItem> MyCollection {get;set;}

<DataGrid ItemsSource="{Binding MyCollection}" />


//anywhere
MyCollection.Clear();

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

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