2013-10-20 42 views
1

我有DataGrid這個DataGrid內容的一些行和列「Id ...」,但我不知道如何獲得價值列「Id」當用戶雙擊鼠標。如何使用事件MouseDoubleClick在DataGrid中獲取值「Id」行?

此代碼爲MouseDoubleClick:

<DataGrid ... > 
     <DataGrid.ItemContainerStyle> 
      <Style TargetType="DataGridRow"> 
       <EventSetter Event="MouseDoubleClick" Handler="Row_DoubleClick"/> 
      </Style> 
     </DataGrid.ItemContainerStyle> 
     ... 
</DataGrid> 

背後代碼:

private void Row_DoubleClick(object sender, MouseButtonEventArgs e) 
    { 
    MessageBox.Show("here I want get column id when user DoubleClick some row"); 
    } 
+0

這可能會幫助你:http://www.scottlogic.com/blog/2008/12/02/wpf-datagrid-detecting-clicked-cell-and-row.html – elgonzo

+0

非常感謝你,可以你寫回答。 – ITInWorld

回答

1

這也將工作

private void Row_DoubleClick(object sender, MouseButtonEventArgs e) 
    { 
    int index = DataGridName.SelectedIndex; 
    MessageBox.Show(index); 
    } 

希望能回答你的問題。 :)

相關問題