2017-11-01 36 views
0

希望のセルをダブルクリックしてDataGridの値を取得することができますか?ダブルクリックで選択したDatagridセルの値を取得

私はこのメソッドを使用しているので、ユーザーは目的のセルを選択してCtrl + Cキーを押してクリップボードに入れることができますが、選択したセルをダブルクリックしてクリップボードに挿入することができます?

private void OrdersGrid_OnCopyingRowClipboardContent(object sender, DataGridRowClipboardEventArgs e) 
{ 
    var currentCell = e.ClipboardRowContent[OrdersGrid.CurrentCell.Column.DisplayIndex]; 
    e.ClipboardRowContent.Clear(); 
    e.ClipboardRowContent.Add(currentCell); 
} 

答えて

0

自分で解決策を見つけました。

ダブルクリックでセル上で選択した値を取得するソリューション。

private void OrdersGrid_OnMouseDoubleClick(object sender, MouseButtonEventArgs e) 
{   
    var cellInfo = OrdersGrid.CurrentCell; 
    { 
     var column = cellInfo.Column as DataGridBoundColumn; 
     if (column != null) 
     { 
       var element = new FrameworkElement() { DataContext = cellInfo.Item }; 
       BindingOperations.SetBinding(element, TagProperty, column.Binding); 
       var cellValue = element.Tag; 
       Clipboard.SetText(cellValue.ToString()); 
     } 
    }     
} 
+0

実際には、WPFを使用している場合は、[WPFコマンド](http://www.wpf-tutorial.com/commands/using-commands/)をよく理解してください。 – SeM

関連する問題