Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
440
Perserve Selected/Active Rows, Active Cell afer DataSource Bind
posted

Hi,

I'd like to preserve the user's row selection and active cell after a databind. Currently if I have the 7th row selected, and I make a call to set the grid's datasource or calling databind(), the grid will select  the first row.

I tried something like the following but it doesn't seem to work.

_lastActiveRow = grid1.ActiveRow

grid1.DataSource = myDataSource

grid1.ActiveRow = _lastActiveRow   ' i also move this line to the InitializeLayout event, but it didn't work.

What's the best way to go about this?

Parents
No Data
Reply
  • 469350
    Offline posted

    Hi,

    This doesn't work because when you set the DataSouce property of the grid, all of the existing row objects are thrown away in favor of a whole new set from the new data source. There's no way that the grid can associated a row in one data source with a row in a new data source. There is no connection between the two objects.

    Assuming that you know that the same data will exist in the grid after you assign the new data source, you could store some key information about the active row, like the primary key, then loop through the grid rows and find the row with the same ID after you have set the DataSource.

Children