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
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.
Thanks Mike!
Just to refer to my first question about the two scrolling functions available. Do you use both firstrow and scrollintoview?
Here is my code:
Private Sub InitGrid_Notifications()
'
Try
' Notifications
Dim Notifications As List(Of NotificationDB) = gManager.GetActiveNotificationsDB(gUserDomain.DomainID, gUser.UserID)
Dim RowIndex As Integer = 0
For i As Integer = 0 To Notifications.Count - 1
Dim Notification As NotificationDB = Notifications.Item(i)
If Notification.TargetDate.ToShortDateString = Date.Now.Date.ToShortDateString Then
RowIndex = i
Exit For
End If
Next
grdNotifications.DataSource = Notifications
Dim argsType As New BeforeRowFilterDropDownEventArgs(grdNotifications.DisplayLayout.Bands(0).Columns("Type"), grdNotifications.Rows, grdNotifications.DisplayLayout.Bands(0).Columns("Type").ValueList)
grdNotifications_BeforeRowFilterDropDown(grdNotifications, argsType)
grdNotifications.ActiveRowScrollRegion.FirstRow = grdNotifications.Rows.Item(RowIndex)
grdNotifications.ActiveRowScrollRegion.ScrollRowIntoView(grdNotifications.Rows.Item(RowIndex))
Catch ex As Exception
MsgBox("InitGrid_Notifications")
End Try
End Sub
This is called when the form is loaded, and once a minute using a timer.
Anyway, it doesn't work as planned...
As you can see, I search for the row to use as first row Before I bind the datasource. When I try to scroll, I guess that I don't have any idea if the InitializeRow events has fired, but I don't know if that affects anything or not.
Ideas?
/Henrik