如何使用事件MouseDoubleClick在DataGrid中获取值“Id”行?

时间:2013-10-20 21:25:40

标签: xaml c#-4.0 datagrid

我有DataGrid这个DataGrid内容的一些行和列“Id ...”,但我不知道当用户双击鼠标时如何获得值列“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");
  }

2 个答案:

答案 0 :(得分:1)

答案 1 :(得分:1)

这也可行

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

希望能回答你的问题。 :)