WPF Datagrid获取所选单元格值 [英] WPF Datagrid Get Selected Cell Value

查看:415
本文介绍了WPF Datagrid获取所选单元格值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要获取datagrid中所选单元格的值,请任何人告诉您如何执行此操作。我使用SelectedCell更改的事件,我该怎么办?

  dataGrid1.CurrentCell 


解决方案

请参阅 DataGrid Class 页面。从该页面:


选择



默认情况下,当用户单击DataGrid中的单元格时,将选择整行,并且用户可以选择多个行。您可以将 SelectionMode 属性设置为指定用户是否可以选择单元格,完整行或两者。设置SelectionUnit属性以指定是否可以选择多个行或单元格,或者仅选择单行或单元格。



您可以获取有关从<一个href =http://msdn.microsoft.com/en-us/library/system.windows.controls.datagrid.selectedcells.aspx =noreferrer> SelectedCells 属性。您可以在中获取有关选择已更改的单元格的信息SelectedCellsChanged事件的SelectedCellsChangedEventArgs 。调用SelectAllCells或UnselectAllCells方法以编程方式选择或取消选择所有单元格。有关详细信息,请参阅DataGrid控件中的默认键盘和鼠标行为。


我已为您添加了相关属性的链接,但我现在已经不在时间了,所以我希望你可以按照链接来获得你的解决方案。


I want to get value for selected cell in datagrid , please anyone tell how to do this. i used SelectedCell changed event , how can i do that?

dataGrid1.CurrentCell

解决方案

Please refer to the DataGrid Class page on MSDN. From that page:

Selection

By default, the entire row is selected when a user clicks a cell in a DataGrid, and a user can select multiple rows. You can set the SelectionMode property to specify whether a user can select cells, full rows, or both. Set the SelectionUnit property to specify whether multiple rows or cells can be selected, or only single rows or cells.

You can get information about the cells that are selected from the SelectedCells property. You can get information about cells for which selection has changed in the SelectedCellsChangedEventArgs of the SelectedCellsChanged event. Call the SelectAllCells or UnselectAllCells methods to programmatically select or unselect all cells. For more information, see Default Keyboard and Mouse Behavior in the DataGrid Control.

I have added links to the relevant properties for you, but I'm out of time now, so I hope you can follow the links to get your solution.

这篇关于WPF Datagrid获取所选单元格值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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