Tuesday, 13 August 2013

Object reference is not set -- WPF -- Rows Deletion

Object reference is not set -- WPF -- Rows Deletion

I am using WPF and Devxpress. I made two operations in my application that
are to add and to delete row from grid. Both are working fine. But if i
drag an drop a column then deletion stops to work to delete multiple rows
at same time. Here code and image, Please answer my query.
private void DeleteButton_Click(object sender, RoutedEventArgs e)
{
if (DXMessageBox.Show("Are You Sure, you Want to Delete?", "Delete
Item-Confirmation", MessageBoxButton.YesNo,
MessageBoxImage.Question) == MessageBoxResult.Yes)
{
try
{
myEntities dbcontext = new myEntities();
Name per = grid.SelectedItem as Name;
dbcontext.Names.Remove(per);
dbcontext.SaveChanges();
Refresh();
}
}
catch (Exception ex)
{
DXMessageBox.Show(ex.Message.ToString());
}}}

Where this code below is working very fine to delete a single row:
Name per = grid.SelectedItem as Name;
dbcontext.Names.Remove(per);
dbcontext.SaveChanges();

No comments:

Post a Comment