WPF: DataGrid Cell Double-click

Is there a better way to determine the row that the user double-clicked in the data grid?

Private Sub ResultsGrid_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Input.MouseButtonEventArgs)
    Dim node As DependencyObject = CType(e.OriginalSource, DependencyObject)
    Do Until TypeOf node Is Microsoft.Windows.Controls.DataGridRow OrElse node Is Nothing
        node = VisualTreeHelper.GetParent(node)
    Loop

    If node IsNot Nothing Then
        Dim data = CType((CType(node, Microsoft.Windows.Controls.DataGridRow)).DataContext, Customer)
        'do something
    End If

End Sub
+3
source share
2 answers
       Dim data = CType(ResultsGrid.SelectedItem, Customer)
0
source

I used C #, just find a way to convert it to VB:

DataRow dr = (DataRow)((System.Data.DataRowView)((Microsoft.Windows.Controls.DataGrid)sender).SelectedItem).Row;
//do your stuff here using the dr variable
0
source

Source: https://habr.com/ru/post/1735163/


All Articles