如何获取所有 DataGrid 的选定项。 (最新)
我目前正在尝试获取用户选择的选定数据网格行的集合(多行选择)。
每行都绑定到一个视觉对象,我想将其显示为选定的“
所以对于数据网格,我添加了这种样式:
<Style TargetType="DataGridRow">
<EventSetter Event="Selected" Handler="DataGrid_RowSelectionChanged" />
</Style>
因此,当用户选择一行时,我会触发一个事件。
但是,当选择一行并进入事件时。所选项目尚未更新,它仍然显示我之前选择的内容 DataGrid.CurrentItem 显示我刚刚单击并即将选择的行,但由于其多重选择,我希望能够获取当前选择的所有行并。我的视觉对象“突出显示”
有没有办法可以从数据网格中获取最新的所选项目列表? 在我选择新行后是否可以使用该事件
? 凯夫
I am currently trying to get a collection of selected datagrid rows selected by the user (multi row selection on).
Each row is binded to a visual object which i want to show as selected"
So for the data grid I added this style:
<Style TargetType="DataGridRow">
<EventSetter Event="Selected" Handler="DataGrid_RowSelectionChanged" />
</Style>
So when the user selects a row I get an event fired.
However, when select a row and into the event. Selected item has not been updated yet and it still shows what I PREVIOUSLY selected. DataGrid.CurrentItem shows the row I just clicked and about to be selected, but since its multi select, I want to be able to get ALL the rows CURRENTLY selected and have my visual object "Highlighted"
Is there a way where I can get a MOST updated list of selected item from datagrid? Is there an event I can use that fires AFTER i selected my new row?
Thanks and Regards,
Kev
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您想要使用 DataGrid.SelectionChanged 事件。
SelectionChangedEventArgs
将包含在选择更改时添加或删除的项目。You want to use the DataGrid.SelectionChanged event. The
SelectionChangedEventArgs
will contain the items which were added or removed at the time of selection changing.