tags:

views:

759

answers:

2

I've got DatGridView bound to BindingSource and I'm trying to scroll it to the bottom after setting it's DataSource.

Binding source's MoveLast() make's last row selected but it doesn't scroll down. I've tried to set FirstDisplayedScrollingRowIndex, but it throws InvalidOperationException with a message "No room is available to display rows".

When I call MoveLast or change FirstDisplayedScrollingRowIndex later, for example in button click event, it works well, but I want to open a new window with DataGridView's last row set as current and visible to user.

+1  A: 

Sounds like your calling FirstDisplayedScrollingRowIndex in the constructor? Try doing it in the load event of the form. Last resort you can do it in the Activate event and set a flag so it only executes once after the form is done drawing itself.

AKoran
+1  A: 

Use the table's "scrollToRowAtIndexPath:atScrollPosition:animated" method.

so you could use it like:

[self.table scrollToRowAtIndexPath:indexPath atScrollPosition:UIScrollPositionMiddle animated:yes];

the "atScrollPosition" tells you where you want your selected row to scroll to on the screen. You can select UIScrollPositionTop, UIScrollPositionMiddle, or UIScrollPositionBottom.

the "animated" field just denotes whether you want the scrolling to be animated as it does it, or just have it appear there right away, I think.

You can create your own indexPath if you need: [NSIndexPath indexPathForRow:(row number or integer value) inSection:0]

"inSection" would be the section you want the path for, if you only have one, just put in 0. Most tables only have one section anyway.

georryan
This link may help as well:http://stackoverflow.com/questions/724892/uitableview-scroll-to-the-top
georryan
Whut? This is WinForms, not Apple's Cocoa :)
frou
Oops, so it is! My bad. =)
georryan