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
Hi,
Okay great sounds good! My intent was to demonstrate that the grid just needed to finish initializing before setting the first row. If you managed to find a simpler solution with this recommendation then by all means stick with it!
If you have any additional questions or if there any parts of your application that you feel are unsafe please send code snippets or your application if possible. Thanks.
Hello Michael!
I implemented your code in my test example and it worked. However, when I implemented the code into my real project I ran into some problems.
The grid that I have in my Project shows one column only, and those column cells are rendered with a usercontrol showing something different. As far as understand, this cell can never get focus and due to that, the afterentereditmode event will not fire. I tried with other approaches like showing more cells but giving them a width of 0, but that doesn't work.
What did solve it was that I replaced the code in your EnterEditModeOnFirstCellInGrid routine with the code that sets the firstrow
That works. . I deleted the event afterentereditmode as well...
So as far as i see it, the begininvoke approach seems to solve this by its own. I am not sure if this is as safe as your complete approach, but it works now.
Please send me some feedback, Before we close this case down.
Good work!
Hello Henrik,
This behavior may very well be a simple timing issue where you are trying to set the first row before the grid has finished initializing. I've worked around this by calling BeginInvoke, placing the first cell in edit mode and then on AfterEnterEditMode I am setting the FirstRow to mimic the click event of your button. There's probably a better way I've just have to regroup with Mike S.
Here is what I added in your sample to make this work. [code]
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
UltraGrid1.BeginInvoke(New MethodInvoker(AddressOf EnterEditModeOnFirstCellInGrid))
End Sub
Private Sub EnterEditModeOnFirstCellInGrid()
Me.UltraGrid1.Focus()Me.UltraGrid1.ActiveCell = Me.UltraGrid1.Rows(0).Cells(0)Me.UltraGrid1.PerformAction(UltraGridAction.ToggleCellSel, False, False)Me.UltraGrid1.PerformAction(UltraGridAction.EnterEditMode, False, False)
Private Sub UltraGrid1_AfterEnterEditMode(sender As Object, e As EventArgs) Handles UltraGrid1.AfterEnterEditMode
UltraGrid1.ActiveRowScrollRegion.FirstRow = mFirstRow
[code]
Keep in mind that I had to enable cell editing. Before in your initialize layout event you were explicitly setting NoEdit on certain columns.
Please review this and let me know if you have any questions.
Here comes a small sample. It is not taken from the "real" project but the behaviour is the same.
I try to set the FirstRow after the grid has been bound to its datasource but nothing happens. When I click the button, it works.
It is the same call, but I guess that the grid isn't ready for it in the first place.
I set the FirstRow variable in the InitializeRow, so that the FirstRow Always is the last one in the grid.
I have read around 15 pages of comments around this topic on your forum and many people have asked about this solution, but you have given no
working solution to anyone as far as I can see. I think that it would be good if you can explain to all of us if this is possible or not. I understand the
problem since the grid is created async, but if there is a solution that works all the time (not based on loading time, timers etc.), it would be great since this feature is really needed. It doesn't feel great to ask the user to click a button to go to the grid rows that shows the messages of today, or what you now want to scroll to in the first place.
Keeping my fingers crossed!
/Henrik
Hi Mike,
I have a problem with row filter in the grid
after adding filter in the grid when i select item in the filter dropdown particular item is not displayed in the grid.
Could you please help on this
Thnaks,
Raju