WPF - DataLog的ObservableCollection - 现在怎样? [英] WPF - ObservableCollection to Datagrid - Now What?

查看:64
本文介绍了WPF - DataLog的ObservableCollection - 现在怎样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我最近从WinForms切换到WPF,请原谅我的noobness。



我有一个网格正在被一个Observable Collection填充。我有菜单按钮,应该添加和删除集合中的条目。添加行更容易,现在我无法尝试删除条目。



首先,用户将选择行,然后单击删除按钮。我试图确定他们在datagrid中选择了哪一行。我一直在尝试Grid.CurrentCell.ToString()或Grid.DisplayMemberValue.ToString()等代码,但我似乎无法获取当前的单元格值。它返回行的空白值或通用名称。即使我可以确定索引,我也可以从中构建它。



谢谢,

Hello,

I have recently switched to WPF from WinForms so please excuse my noobness.

I have a grid is being populated by an Observable Collection. I have menu buttons that are supposed to add and remove entries from the collection. Adding the rows was easier, now i''m having trouble trying to remove an entry.

First, the User will select the row, then click the delete button. I am trying to determine which row they have selected in the datagrid. I have been trying code such as Grid.CurrentCell.ToString() or Grid.DisplayMemberValue.ToString() but I cannot seem to get the current cell value. It returns a blank value or a generic name for the row. Even if I could determine the index, I could build it from that.

Thank you,

推荐答案

查看 SelectedItem Property [ ^ ]

SelectedValue Property [ ^ 使用 SelectedValuePath Property [ ^ ]。

对于添加和删除操作,您应该使用命令,并将项目用于添加或删除应作为命令参数提供。
Look at the SelectedItem Property[^]
or SelectedValue Property[^] with the SelectedValuePath Property[^].
For the Add and Delete operations you should use commands, and the item to add or delete should be provided as command parameter.


这篇关于WPF - DataLog的ObservableCollection - 现在怎样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆