[英]Deleting Rows from GridView
I have an RadGridView
. 我有一个
RadGridView
。 When users clicks on a row
and then click my Delete
button I call a method to delete that row from my database. 当用户单击
row
,然后单击“ Delete
按钮时,我调用了一种从数据库中删除该行的方法。 But it shows this entry on the GridView
. 但它会在
GridView
上显示此条目。 I can manually call the LoadGridView()
method again to show the user that the entry has been deleted but isn't there any other built-in method that can remove that item from the GridView too? 我可以再次手动调用
LoadGridView()
方法,以向用户显示该条目已被删除,但是没有其他任何内置方法也可以从GridView中删除该项目吗?
Here is the Delete Click EventHandler: 这是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();
}
}
The grid binding: 网格绑定:
List<Product> productList = new List<Product>();
this.grdProductGrid.ItemsSource = productList;
Since you're using a List
as a source, you need to remove the item from the list and manually force the RadGridView
to refresh; 由于您使用
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.