I'm using a datagrid in my program,and bind it with 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; 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. now,any idea to clear rows?? thx
if you have a ObservableCollection bind to your DataGrid ItemsSource simply use .Clear()
public OberservableCollection<MyItem> MyCollection {get;set;}
<DataGrid ItemsSource="{Binding MyCollection}" />
//anywhere
MyCollection.Clear();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.