2010-03-03 135 views
3

有没有更好的方法来确定用户在数据网格中双击的行?WPF:DataGrid单元格双击

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 

回答

0
 Dim data = CType(ResultsGrid.SelectedItem, Customer) 
0

我使用C#只是找到一种方法将其转换为VB:

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