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?
The grid follows the current record of the data source to which it is bound by default, meaning you would just have to set the binding manager's Position property to the index of the record that you want to "select":
UltraGrid grid = this.ultraGrid;BindingManagerBase bm = grid.BindingContext[grid.DataSource, grid.DataMember];bm.Position = 0;
Note that you can also select and activate an UltraGridRow programmatically; set the UltraGrid.ActiveRow property to activate the row, and use the Rows property of the Selected object to select a row:
this.ultraGrid.ActiveRow = row;this.ultraGrid.Selected.Rows.Add( row );
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...
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.
Manager - Windows Forms Development