[英]Deleting Rows from GridView
我有一个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;
由于您使用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;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.