C# 在运行时选择GridEx中的行

C# 在运行时选择GridEx中的行,c#,janus,gridex,C#,Janus,Gridex,我正在使用Janus GridEx控件。我使用计时器每分钟用数据库中的数据更新网格。如果用户在从数据库更新数据时选择了一行,那么在更新完成后如何重新选择该行?您应该在刷新网格之前存储所选行的索引,然后在更新后将所选行设置为该值。比如: int row = myGrid.Row; // Perform update try { vJanusDataGridMeasures.Row = row; } // The row index that was selected no longer

我正在使用Janus GridEx控件。我使用计时器每分钟用数据库中的数据更新网格。如果用户在从数据库更新数据时选择了一行,那么在更新完成后如何重新选择该行?

您应该在刷新网格之前存储所选行的索引,然后在更新后将所选行设置为该值。比如:

int row = myGrid.Row;

// Perform update

try
{
    vJanusDataGridMeasures.Row = row;
}
// The row index that was selected no longer exists.
// You could avoid this error by checking this first.
catch (IndexOutOfRangeException)
{
    // Check to see if there are any rows and if there are select the first one
    if(vJanusDataGridMeasures.GetRows().Any())
    {
        vJanusDataGridMeasures.Row = 0;
    }
}

您应该在刷新网格之前存储选定行的索引,然后在刷新后将选定行设置为该值。比如:

int row = myGrid.Row;

// Perform update

try
{
    vJanusDataGridMeasures.Row = row;
}
// The row index that was selected no longer exists.
// You could avoid this error by checking this first.
catch (IndexOutOfRangeException)
{
    // Check to see if there are any rows and if there are select the first one
    if(vJanusDataGridMeasures.GetRows().Any())
    {
        vJanusDataGridMeasures.Row = 0;
    }
}