如何使用数据网格单元格的列和行索引值设置其值?
如何使用单元格的列和行索引将值插入到特定的数据网格单元格中。我将行和列索引保存为整数。
我得到的索引如下。我基本上获取单元格值、列索引和行索引,并将其作为序列化 XML 发送到 java,java 将其发送回并需要将其放在同一个单元格中。
int column = dataGrid2.CurrentCell.Column.DisplayIndex;
int row = dataGrid2.SelectedIndex;
谢谢,
How can i insert a value into a specific datagrid cell by using the cells column and row indexs. I have the Row and Column index saved as ints.
I got the indexs as below. Im basically taking the cell value, the column index and the row index and sending as a serialized XML to java which is sending it back and needs to put it in the same cell.
int column = dataGrid2.CurrentCell.Column.DisplayIndex;
int row = dataGrid2.SelectedIndex;
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果你使用DataGrid你可以尝试一下
If you use DataGrid you can try it
对于数据网格,您可以通过 Items 属性访问行。单元格是某个项目的集合。
只要数据在当前页面生命周期期间已绑定到数据网格,此操作就有效。如果情况并非如此,那么我相信您将被困在控制中。
For a datagrid you access rows through the Items property. The cells are a collection on an item.
This works as long as the data has been bound to the datagrid during the current page life-cycle. If this is not the case then I believe you are stuck walking the controls.
要以编程方式更新 WPF DataGridCell,可能有多种方法...
其中一种方法是更新绑定数据项本身中的值。这样,属性更改通知将为所有订阅的视觉对象(包括 DataGridCell 本身)触发...
反射方法
对于
DataGridComboBoxColumn
,您必须提取SelectedValuePath
并使用它来代替propertyName
。其他方法包括将单元格置于编辑模式并使用
EditingElementStyle
中的某些行为更新其内容值...我发现这很麻烦。如果您确实需要,请告诉我。
To update a WPF DataGridCell programmatically, there could be many ways...
One of the ways is to update value in the bound data item itself. This way the property change notifications will fire for all subscribed visuals including the DataGridCell itself...
Reflection approach
For
DataGridComboBoxColumn
you would have to extract theSelectedValuePath
and use that in place ofpropertyName
.Otherways include putting cell in edit mode and updating its content value using some behavior in the
EditingElementStyle
... I find this cumbersome.Do let me know if you really need that.
我使用了基于 WPF 的变体 - 它的示例执行了整行并且成功了!:
PS:请确保使用对该列有效的值类型(可能通过 switch 语句)。
例如:
打开 propertyName 或 propInfo... propInfo.SetValue(boundItem, (type) NEWVALUE, new object[] {});
I used a variation based upon WPF-it's example to do the whole row and it worked!:
PS: Be sure that you use value types that are valid for the column (perhaps via a switch statement).
e.g.:
switch on propertyName or propInfo... propInfo.SetValue(boundItem, (type) NEWVALUE, new object[] {});