2016-09-24 106 views
0

我有一個數據網格,當我在這個數據網格上加載數據時,我想關注選定的行。但是我沒有通過索引獲得排名。如何在wpf數據網格中按索引獲取行

if (gridAppointment.SelectedIndex >= 0) 
{ 
    gridAppointment.ScrollIntoView(gridAppointment.Items[gridAppointment.SelectedIndex]); 
    DataGridRow row = (DataGridRow)gridAppointment.ItemContainerGenerator.ContainerFromIndex(
     gridAppointment.SelectedIndex); 
    if (row != null) 
     row.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));            
} 
+0

那麼使用SelectedItem呢? –

回答

0

當您選擇該行的下一個條件是真實的,你能得到這樣

if (gridAppointment.SelectedIndex >= 0) 
    { 
     DataRowView dataRow = (DataRowView)gridAppointment.SelectedItem; 
     int i = dataRow.Row.ItemArray[0].ToString(); 

// ItemArray所有單元格值[1]是下一列等。 }

+0

我正在使用DATAGRID而不是DATAGRIDVIEW,所以這不是我的工作 –

+0

即時通訊也使用** DataGrid ** – Sulyman

+0

我使用它,但它給了我錯誤。錯誤: - 「無法投射'ClinicManagement.Entity.GetAppointmentList_Result'類型的對象來鍵入'System.Data.DataRowView'。」 –

相關問題