WPF DataGrid通过点击单元格获取所在的行号

WPF DataGrid通过点击单元格获取所在的行号

        private void DataGridCell_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            DataGridCell cell = (DataGridCell)sender;
            DataGridCellInfo cellinfo = new DataGridCellInfo(cell);
            DataRowView? drview = cellinfo.Item as DataRowView;
            if (drview != null)
            {
                var row = drview.Row;
                var tbl = row.Table;
                int rowIndex = tbl.Rows.IndexOf(row);
                MessageBox.Show(rowIndex.ToString());
            }
        }

你可能感兴趣的:(C#,wpf,wpf)