我有RadGridView
。当用户点击row
然后点击我的Delete
按钮时,我会调用一种方法从我的数据库中删除该行。但它在GridView
上显示了此条目。我可以再次手动调用LoadGridView()
方法向用户显示该条目已被删除但是没有任何其他内置方法可以从GridView中删除该项目吗?
这是Delete Click EventHandler:
private void OnDeleteClick(object sender, RoutedEventArgs e)
{
Product deleteProduct = new Product();
foreach (Product product in this.grdProductGrid.SelectedItems)
{
deleteProduct = product;
}
if (deleteProduct != null)
{
_service.DeleteProductAsync(deleteProduct);
this.grdProductGrid.SelectedItems.Clear();
}
}
网格绑定:
List<Product> productList = new List<Product>();
this.grdProductGrid.ItemsSource = productList;
答案 0 :(得分:1)
由于您使用List
作为来源,因此您需要从列表中删除该项并手动强制RadGridView
进行刷新;
// Temporarily store the ItemSource as a List in tmp
List tmp = (List)this.grdProductGrid.ItemsSource;
// Remove the item from the List
tmp.Remove(deleteProduct);
// Force a refresh by "tricking" RadGridView
// that it's getting an entirely new ItemsSource
this.grdProductGrid.ItemsSource = null;
this.grdProductGrid.ItemsSource = tmp;