2014-04-29 59 views

回答

1

您可以使用此helper方法获取行索引:

public static class DataGridHelper 
{ 
    static public int GetRowIndex(DataGrid dataGrid, DataGridCellInfo dataGridCellInfo) 
    { 
     DataGridRow dgrow = (DataGridRow)dataGrid.ItemContainerGenerator.ContainerFromItem(dataGridCellInfo.Item); 
     if (dgrow != null) 
      return dgrow.GetIndex(); 

     return -1; 
    } 
} 

使用它像这样在适当的事件:

int rowIndex = DataGridHelper.GetRowIndex(yourDataGrid, yourDataGrid.SelectedCells[0]); 
+0

谢谢你这么多的Eirik!我会尽快尝试。 –

+0

它像魅力一样工作! :-)百万感谢你 –