使用Winforms'DataGridView
,可以使用HitTest
来确定鼠标向下(和其他事件)的列和行索引。是否有一个datagrid鼠标按下命中测试来获取点击的行和列索引?
Dim hti As DataGridView.HitTestInfo = sender.HitTest(e.X, e.Y)
是否有类似WPF的DataGrid
?我需要获取MouseLeftButtonDown
事件的行和列索引。
使用Winforms'DataGridView
,可以使用HitTest
来确定鼠标向下(和其他事件)的列和行索引。是否有一个datagrid鼠标按下命中测试来获取点击的行和列索引?
Dim hti As DataGridView.HitTestInfo = sender.HitTest(e.X, e.Y)
是否有类似WPF的DataGrid
?我需要获取MouseLeftButtonDown
事件的行和列索引。
这比这更复杂,但以下链接应该有助于获取行和列的索引。
WPF的DataGrid - 检测已单击列,单元格和行:http://blog.scottlogic.com/2008/12/02/wpf-datagrid-detecting-clicked-cell-and-row.html
WPF DataGrid - get row number which mouse cursor is on
你将不得不使用VisualTreeHelper类遍历视觉元素组成的DataGrid作为如上所述。
对于那些可能希望避免在这里我的搜索是总的代码,我结束了令人费解在一起能够提供:
能够暴露行上列的值。
的代码进入的MouseLeftButtonUp事件和DGrid1是
Dim currentRowIndex As Integer = -1
Dim CurrentColumnIndex As Integer = -1
Dim CurrentColumnHeader As String = ""
Dim Myrow As DataRowView = Nothing
Dim dep As DependencyObject = DirectCast(e.OriginalSource, DependencyObject)
While dep IsNot Nothing And Not TypeOf dep Is DataGridCell And Not TypeOf dep Is Primitives.DataGridColumnHeader
dep = VisualTreeHelper.GetParent(dep)
If dep IsNot Nothing Then
If TypeOf dep Is DataGridCell Then
Dim cell As DataGridCell = DirectCast(dep, DataGridCell)
Dim col As DataGridBoundColumn = DirectCast(cell.Column, DataGridBoundColumn)
Myrow = DGrid1.SelectedItem
CurrentColumnHeader = col.Header.ToString
CurrentColumnIndex = col.DisplayIndex
currentRowIndex = DGrid1.Items.IndexOf(DGrid1.CurrentItem)
Exit While
End If
End If
End While
If currentRowIndex = -1 OrElse CurrentColumnIndex = -1 OrElse CurrentColumnHeader = "" OrElse Myrow Is Nothing Then Exit Sub
'code to consume the variables from here
Dim strinwar As String = Myrow.Item("header name or index").ToString()
不幸的是我已经尝试了约3个不同的C到VB转换器和非已经能够转换代码到VB – user1500403
电网的名字我已经能够使用该文章,谢谢。 – user1500403