I have an RadGridView
. When users clicks on a row
and then click my Delete
button I call a method to delete that row from my database. But it shows this entry on the 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?
Here is the 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;
// 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;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.