[英]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.