简体   繁体   English

来自DataGrid事件CellEditEnding的更新列表项

[英]Update List item from DataGrid event CellEditEnding

I've loaded datagrid from a LIST. 我已经从LIST加载了datagrid。 On every click event to a button it loads data to the LIST and eventually update the DataGrid by resetting the source. 对按钮的每次单击事件,它将数据加载到LIST中,并最终通过重置源来更新DataGrid。

Next thing I would like to do is to edit the values in Cell of that DataGrid and add it back to the List. 接下来,我想编辑该DataGrid的Cell中的值,并将其添加回List。

I've used struct to add data to List Items and DataGrid. 我已经使用struct将数据添加到List Items和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. 这是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}

Help me out... 帮帮我...

我仍然不清楚您的问题,但可以使用CellEditEnding事件中的DataGridCellEditEndingEventArgs来获取所需的值........ 属性链接可能会为您提供帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM