过滤后编辑 wpf datagrid 行
我有一个 WPF C# 数据网格,我可以使用 SqlDataAdapter 对其进行过滤,并使用 ItemsSource 属性显示它。
我还可以在过滤之前更新/删除行,但不能在过滤之后更新/删除行。
diamedbEntities objContext;
Sender objSendToEdit;
private void Window_Loaded(object sender, RoutedEventArgs e)
{
objContext = new diamedbEntities();
dgEmp.ItemsSource = objContext.Senders;
}
private void dgEmp_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
objSendToEdit = dgEmp.SelectedItem as Sender;
}
private void btnDelete_Click(object sender, RoutedEventArgs e)
{
if (objSendToEdit == null)
{
MessageBox.Show("Cannot delete the blank Entry");
}
else
{
objContext.DeleteObject(objSendToEdit);
objContext.SaveChanges();
MessageBox.Show("Record Deleted..");
}
}
过滤后objSendToEdit为null。 我该如何解决这个问题?
I have a WPF C# datagrid which I can filter through with an SqlDataAdapter and display it with the ItemsSource property.
I can also update/delete rows before filtering but not after.
diamedbEntities objContext;
Sender objSendToEdit;
private void Window_Loaded(object sender, RoutedEventArgs e)
{
objContext = new diamedbEntities();
dgEmp.ItemsSource = objContext.Senders;
}
private void dgEmp_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
objSendToEdit = dgEmp.SelectedItem as Sender;
}
private void btnDelete_Click(object sender, RoutedEventArgs e)
{
if (objSendToEdit == null)
{
MessageBox.Show("Cannot delete the blank Entry");
}
else
{
objContext.DeleteObject(objSendToEdit);
objContext.SaveChanges();
MessageBox.Show("Record Deleted..");
}
}
After filtering objSendToEdit is null.
How can I solve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
http://msdn.microsoft.com/en-我们/库/cscsdfbt(v=VS.100).aspx
您想用 objSendToEdit = dgEmp.SelectedItem as Sender; 做什么?
http://msdn.microsoft.com/en-us/library/cscsdfbt(v=VS.100).aspx
What are you trying to do with
objSendToEdit = dgEmp.SelectedItem as Sender;
?这是因为过滤器必须清除选择,从而使 objSendToEdit 为空。
您应该在过滤后立即将
objSendToEdit
重新选择回数据网格。让我知道这是否有帮助。
This is because filter must be clearing the selection thus making
objSendToEdit
null.You should re-select the
objSendToEdit
back onto the data grid immediately after filtering.Let me know if this helps.