[英]How to get row by index in wpf datagrid
我有一個數據網格,當我在此數據網格上加載數據時,我要關注選定的行。 但我沒有得到索引。
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));
}
當選擇該行時,下一個條件為true,這樣便可以獲取所有像元值。
if (gridAppointment.SelectedIndex >= 0)
{
DataRowView dataRow = (DataRowView)gridAppointment.SelectedItem;
int i = dataRow.Row.ItemArray[0].ToString();
// ItemArray[1] is the next column and so on.
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.