首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

wpf DataGrid 怎么设置某行为选中状态

2013-03-21 
wpf DataGrid 如何设置某行为选中状态设置第n行为选中 应该怎么做?[解决办法]dataGrid.SelectedIndex设置

wpf DataGrid 如何设置某行为选中状态
设置第n行为选中 应该怎么做?
[解决办法]
dataGrid.SelectedIndex设置这个呢。
[解决办法]

public static DataGridRow GetDataGridRow(DataGrid datagrid, int rowIndex)
        {
            DataGridRow row = (DataGridRow)datagrid.ItemContainerGenerator.ContainerFromIndex(rowIndex);
            if (row == null)
            {
                datagrid.UpdateLayout();
                //datagrid.ScrollIntoView(datagrid.Items[rowIndex]);
                row = (DataGridRow)datagrid.ItemContainerGenerator.ContainerFromIndex(rowIndex);
                row.IsSelected = true;
            }
            return row;
        }

热点排行