从 GridView 中删除行
Deleting Rows from GridView
我有一个 RadGridView
。当用户点击 row
然后点击我的 Delete
按钮时,我调用了一个方法从我的数据库中删除该行。但它在 GridView
上显示此条目。我可以再次手动调用 LoadGridView()
方法来向用户显示该条目已被删除,但是是否有任何其他内置方法也可以从 GridView 中删除该项目?
这里是删除点击事件处理程序:
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;
我有一个 RadGridView
。当用户点击 row
然后点击我的 Delete
按钮时,我调用了一个方法从我的数据库中删除该行。但它在 GridView
上显示此条目。我可以再次手动调用 LoadGridView()
方法来向用户显示该条目已被删除,但是是否有任何其他内置方法也可以从 GridView 中删除该项目?
这里是删除点击事件处理程序:
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;