private void ButtonEdit_Click(object sender, RoutedEventArgs e) { if (ListBox1.SelectedIndex < 0) { MessageBox.Show("Select employee"); return; } Employee editEmployee = ListBox1.SelectedItem as Employee; WindowNewEmployee w1 = new WindowNewEmployee(); w1.Title = "Edit employee data"; w1.Owner = this; int id = editEmployee.EmployeeID; w1.Employee = editEmployee; if (w1.ShowDialog() == true) { editEmployee = w1.Employee; editEmployee.EmployeeID = id; int result = eDal.ChangeEmployee(editEmployee); if (result == 0) { ShowEmployees(); ListBox1.SelectedIndex = employeeList .FindIndex(a => a.EmployeeID == id); MessageBox.Show("Employee data changed"); } else { MessageBox.Show("Error"); } } }