2012-02-27 47 views
1

我正在使用Janus GridEx控件。我正在使用計時器每分鐘更新數據庫中的數據。如果用戶在從數據庫更新數據時選擇了一行,那麼如何在更新完成後重新選擇該行?在運行時在GridEx中選擇行

回答

4

您應該在刷新網格之前存儲所選行的索引,然後將所選行設置爲該值。例如:

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; 
    } 
}