private void btnDel_Click(object sender, RoutedEventArgs e) { if (DGUser.SelectedItem != null) { DataRowView DRV = (DataRowView)DGUser.SelectedItem; string Name = DRV.Row[0].ToString();//获取选中行的name列内容 if (Name == UserName)//UserName为当前的登陆者 { MessageBox.Show("不允许删除自己,请周知!"); } else { MessageBoxResult result = MessageBox.Show("确定要删除用户?", "提示", MessageBoxButton.YesNo);//弹出删除对话框 switch (result) { case MessageBoxResult.Yes: DelUserData(Name);//调用函数,删除数据库 DRV.Delete();//删除行 MessageBox.Show("删除成功!"); break; case MessageBoxResult.No: break; } } } }