开发者

How can show some item in my list when bind my list to a grid?

I have a list that bound to a grid. My list items have properties like RunTimeState. The user can select each item in the grid and delete it. When an item开发者_JS百科 is deleted its RunTimeState is set to Deleted. How can I get my grid to not show these deleted items?


Whenever your item is deleted, you should raise INotifyPropertyChanged.PropertyChanged event with property name set to grid data source. And that property should filter the items or the item should be removed from your collection before.

A code can look like this:

var myDataSource = ...;

public void DeleteItem(Item item)
{
  item.RunTimeState = RunTimeState.Deleted;
  // you can remove the item from the myDataSource here or filter it later
  PropertyChanged(this, new PropertyChangedEventArgs("DataSource"));
}

public IList<Item> DataSource 
{
  get { return myDataSource; }
  // or
  get 
  { 
    return myDataSource.Where(i => i.RunTimeState != RunTimeState.Deleted).ToList(); 
  }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜