检测何时在 DataGrid 中编辑行
我一直在尝试谷歌搜索,但无法找到适合我的解决方案。
我有一个 DataGrid,它显示 SQL 表中客户端不知道的一些信息。 客户端只需向服务器发送请求并获取 List
我需要检测用户何时对行进行更改,并且需要用户输入的新值。 目前我正在使用 RowEditEnding 事件。然后处理该事件的方法可以:
private void editRowEventHandler(object sender, DataGridRowEditEndingEventArgs e)
{
SomeClass sClass = e.Row.DataContext as SomeClass;
// Send sClass to the server to be saved in the database...
}
这给我正在编辑的行。但它给了我更改前的行,并且我无法弄清楚如何在更改发生后获取行。
这里有没有人知道我该如何做到这一点,或者可以为我指出一个我可能能够找到答案的方向?
I've been trying to google this but have been unable to find a solution that works for me.
I have a DataGrid that is displaying some info from a SQL table that the client dosn't know about.
The client just sends a request to the server and gets a List<SomeClass> as a response that it then displays in a DataGrid.
I need to detect when the user makes change to a row and I need the new values that the user entered.
Currently I'm using RowEditEnding event. And the method that handles this event can then:
private void editRowEventHandler(object sender, DataGridRowEditEndingEventArgs e)
{
SomeClass sClass = e.Row.DataContext as SomeClass;
// Send sClass to the server to be saved in the database...
}
This gives me the row that was being edited. But it gives me the row before the changes, and I'm unable to figure out how to get the row after the changes happen.
Is there anyone here that knows how I can do this or can point me in a direction where I might be able to find out?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请参阅此处的讨论,以避免逐个单元地读出。
See the discussion here, to avoid reading out cell-by-cell.
就您而言,您正在尝试检测对象的变化。它归结为 SomeClass 的属性,因此您需要关注“Cell”而不是“Row”
假设您的数据网格是 resultGrid,我想出以下代码:
“e”还包含有关行和列的信息细胞。因此您将知道单元格正在使用哪个编辑器。在这种情况下,我假设它是一个文本框。
希望有帮助。
In your case, you are trying to detect the change in object. It comes down to the properties of the SomeClass, thus you need to focus on "Cell" instead of "Row"
Assuming your datagrid is resultGrid, i come up with the below code:
the "e" also contains information about Row and Column of the Cell. Thus you will know which editor the cell is using. In this case, i assume that it is a textbox.
Hope it help.