从 DataGrid 事件 CellEditEnding 更新列表项
我已经从列表加载了数据网格。在按钮的每次单击事件上,它都会将数据加载到 LIST 中,并最终通过重置源来更新 DataGrid。
接下来我想做的是编辑该 DataGrid 单元格中的值并将其添加回列表中。
我使用 struct 将数据添加到列表项和 DataGrid。 这是结构:
public struct MyData {
public string item{get;set;}
public int number{get;set;}
}
这是 CellEditEnding 事件的代码。
int index = DataGrid1.SelectedIndex;
// I KNOW PROBLEM IS HERE as it selects the previous value not the changed value.
MyData foo = (MyData)DataGrid1.SelectedItem;
DataGrid1[index] = new MyData{item=foo.item.ToString(), number = 5}
帮帮我吧...
I've loaded datagrid from a LIST. On every click event to a button it loads data to the LIST and eventually update the DataGrid by resetting the source.
Next thing I would like to do is to edit the values in Cell of that DataGrid and add it back to the List.
I've used struct to add data to List Items and DataGrid.
This is the struct:
public struct MyData {
public string item{get;set;}
public int number{get;set;}
}
Here is a code for CellEditEnding event.
int index = DataGrid1.SelectedIndex;
// I KNOW PROBLEM IS HERE as it selects the previous value not the changed value.
MyData foo = (MyData)DataGrid1.SelectedItem;
DataGrid1[index] = new MyData{item=foo.item.ToString(), number = 5}
Help me out...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我仍然不清楚你的问题,但使用
CellEditEnding 事件中的
DataGridCellEditEndingEventArgs
来获取所需的值........ 此属性链接可能会对您有所帮助。Your problem is still not clear to me but use
DataGridCellEditEndingEventArgs
in the CellEditEnding Event to gt the required values........ this link for Properties that might help you.