簡體   English   中英

WPF:DataGrid單元格雙擊

[英]WPF: DataGrid Cell Double-click

有沒有比這更好的方法來確定用戶在數據網格中雙擊的行?

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

我用過c#只是找到一種方法將它轉換為VB:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM