簡體   English   中英

從GridView刪除行

[英]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(deleteP‌​roduct); 

// 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM