如何在wpf数据网格中按索引获取行
我有一个数据网格,当我在这个数据网格上加载数据时,我想关注选定的行。但是我没有通过索引获得排名。如何在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));
}
当您选择该行的下一个条件是真实的,你能得到这样
if (gridAppointment.SelectedIndex >= 0)
{
DataRowView dataRow = (DataRowView)gridAppointment.SelectedItem;
int i = dataRow.Row.ItemArray[0].ToString();
// ItemArray所有单元格值[1]是下一列等。 }
我正在使用DATAGRID而不是DATAGRIDVIEW,所以这不是我的工作 –
即时通讯也使用** DataGrid ** – Sulyman
我使用它,但它给了我错误。错误: - “无法投射'ClinicManagement.Entity.GetAppointmentList_Result'类型的对象来键入'System.Data.DataRowView'。” –
那么使用SelectedItem呢? –