I have a readonly UltraGrid that is bound to a datasource that contains an ID column as the PK for the collection. I would like to select a specific row based upon the ID and highlight/activate it programmatically. The grid should scroll to the proper location if the selected row is not visible.
QUESTION: Is there an example of how I can do this?
We are on version 15.2.20152.2023
Hi ljksui,
What version of the grid are you using? There were some old bugs a long time ago where the appearances on a row weren't properly refreshed so a row might maintain the selected or active appearance even after it was no longer selected/active.
Showing a MessageBox doesn't have any effect on the ActiveRow or the SelectedRows, by the way. Nor would losing focus on the grid. Showing a MessageBox would take the ActiveCell out of edit mode (if it was in edit mode). But that's not really the same thing.
When I choose a different row in my grid I have a Message Box prompt asking if I want to save. This message box seems to make the grid lose focus so there are no rows selected. After the save, the data gets refreshed in the grid and the focus goes back to the first row. The first row is getting the focus by setting the grid.ActiveRow.
This seems to work initially but when I hover over a field in the active row, the ActiveAppearance.BackColor goes away. If I select another row in the grid, the selector indicator still shows on the first row plus also on the new row I have selected. It almost seems as if the grid row thinks it has the focus but it really doesn't.
If I just save without selecting another row it seems to work fine. Seems to be only when the row loses focus and then the grid reloads.
Any suggestions?
Hi Swetha,
If you are only dealing with a single row here, then I'd recommend that you set grid.ActiveRow to the row you want, instead of selecting the row. That will highlight the row (by default), and also scroll that row into view automatically.
But if that won't work for you, then what you can do is use the grid.ActiveRowScrollRegion. This object has a FirstRow property which determines the first visible row, so you can set that to the row you want. You could also use the ScrollRowIntoView method if you don't care if the row is first, but just want it to be somewhere in the viewable area.
Brian,
If there are too many rows in the grid and the grid has a scroll bar , how to get that particular row in view? system shud automatically scroll the grid to that row...
Thanks!
Swetha.