Programmatically selecting/activating a row?

Answered (Not Verified) This post has 0 verified answers | 3 Replies | 2 Followers Thread's RSS feed.

ericgeas
Points 1,170
Replied On: Wed, Sep 16 2009 5:05 PM Reply

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?

  • Post Points: 20

All Replies

Answered (Not Verified) Replied On: Thu, Sep 17 2009 9:55 AM Reply

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

  • Post Points: 20
Swe2
Points 1,475
Replied On: Sat, Mar 26 2011 2:39 PM Reply

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.

  • Post Points: 20
Mike Saltzman
Points 443,105
Infragistics Employee
Answered (Not Verified) Replied On: Mon, Mar 28 2011 9:59 AM Reply
Suggested by Tess1243

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.

 

Mike Saltzman

Manager - Windows Forms Development

Infragistics, Inc.

  • Post Points: 5
Page 1 of 1 (4 items) | RSS