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
2745
Problem when using ScrollRowIntoView
posted

Hello!

I have a grid in which I show messages. All messages have a date column and the rows are sorted according to date.

So we have old messages, messages that are for the future and we have "hot" messages which are to be shown today so to speak.

What I want to do is to scroll the grid automatically to get the first message today to appear in the top of the grid.

After a lot of reading in here within this topic, I still couldn't find a solution that worked.

So I am kindly asking for help.

What I have is a grid with many columns but all of them except one is hidden. I have changed the visible cell data using the editor component, and this is done in InitializeRow event.

I am binding the datasource when the form is loaded, and then I use the InitializeLayout for column changes and the InitializeRow for theeditor component work.

I also evaluate which row that should be in the top of the grid in InitializeRow event.

My problems are:

1. I have placed the ScrollIntoViewCode the row after the datasource binding. I get a timing problem the first time I run it since the row to be placed in the top isn't set. Where shall I place the code to functionally all the time. I have used both:

grdNotifications.ActiveRowScrollRegion.FirstRow = ActiveRow_Notifications
grdNotifications.ActiveRowScrollRegion.ScrollRowIntoView(ActiveRow_Notifications)

Which one is to prefer?

2. Secondly, when I have a row to scroll for, it looks like the rows are squezed together. 

I have set the row height to AutoFixed, but since I have a usercontrol as the editor component, it might be the problem. It looks like the grid returns to standard row height after the scrolling.

I have attached to images that might help out

Parents
  • 469350
    Suggested Answer
    Offline posted

    1) This could very well be a timing issue if you the grid has not yet painted. There are two ways you could get around that.

    One would be to wait for the grid to Paint. So use the Paint event of the grid and use a flag so that you only set the FirstRow the first time the event fires. You could even disconnect the event handler after the first Paint if you want.

    Another option would be to force the grid to paint earlier, before you set the FirstRow. You could do that by calling grid.Update();

    2) It's hard to tell, but it sounds like you are using UltraControlContainerEditor. If that's the case, then when you AutoSize the row height, the grid will call GetPreferredSize on your RenderingControl. So you probably need to override GetPreferredSize and make sure it returns the ideal height for your control.

Reply Children