delete row from DataGrid and EF table

  • Thread starter Thread starter zleug
  • Start date Start date
Z

zleug

Guest
Hi All.

The UI layer has DataGrid one of the column has delete button. That is method that I try to delete DataGrid row

private void DeleteEmployee_BTn_Click(object sender, RoutedEventArgs e)
{
if (!(Employee_DG.SelectedValue == null))
{
if (MessageBox.Show("Are you sure you want to delete", "Are you sure?", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
{
int empid = (int) Employee_DG.SelectedValue;
ProjectAdapter.DeleteEmployee(empid);
}
}
}

When I run application and hit Delete button in line
int empid = (int) Employee_DG.SelectedValue;

I got error message:
System.InvalidCastExeptions: 'Specified cast is not valid.'

When I'm gebugging step by step and check value in SelectedValue it displays rows values. How modify the code to retrieve only EmployeeId value?

Thanks.

Continue reading...
 
Back
Top