I'm not sure where to start looking to handle this - key mapping, or trying to modify the scroll activity, or.....
Ultragrid 9.2
I have a main band, Band 0, with 2 children, Band 1 and Band 2. Bands 1 & 2 are at the same 'level' - they both show up when you expand a row in band 0.
When all are expanded for a Band 0 row, they take up the full display, no part of the child row is below the visible grid.
When the user presses pageup/down, or clicks in the scroll band or arrows, I want the next Band 0 row to be positioned at the top of the grid. Right now it just activates up the next band 1, then band 2, then it needs to scroll to see the next band 0 , band 1, band 2....
I want a 'page' to be a full set of expanded band 0,1,2. I thought page up/down flipped through a single band, but I can't get the Band 0 to move to the top of the grid if it's displayed lower down in the grid.
Where should I start looking?
Thanks, Robin
Hi Robin,
There are a lot of unknowns here regarding the exact behavior you want. But this should get you started in the right direction:
private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e) { e.Layout.ScrollBounds = ScrollBounds.ScrollToFill; } private void ultraGrid1_KeyDown(object sender, KeyEventArgs e) { UltraGrid grid = (UltraGrid)sender; switch (e.KeyCode) { case Keys.PageDown: case Keys.PageUp: UltraGridRow row = grid.ActiveRowScrollRegion.FirstRow; if (row == null) return; while (row.Band.Index != 0) row = row.ParentRow; SiblingRow siblingRow = (e.KeyCode == Keys.PageDown) ? SiblingRow.Next : SiblingRow.Previous; row = row.GetSibling(siblingRow, false); if (row != null) grid.ActiveRowScrollRegion.FirstRow = row; e.Handled = true; break; } }
Thank you Mike! Above and beyond as usual - you are extremely helpful.You must dream this stuff lol....
I think this is really close to what I need. I was getting tangled up into which event to use and how to use the .FirstRow. Learn something new every day!
Robin
I'm back. Are there any documents around that talk about the interaction of MouseWheel events and Ultragrid scrolling in multibands?
Using your suggestions my key up/down works perfectly, but the mousewheel gets tangled up in the system definition of how many lines to scroll (I'm assuming), because if I put similar code in MouseWheel that's in my key down code, I can see it work - the correct row is FirstRow, but then the system takes over and I get a display that starts in the middle of a band.
I've tried subclassing UltraGrid, but I lose designer support (and this is a complete rowlayout - I need the designer).
Any hints on how to untangle the MouseWheel event from the system so I can do what I want?
Thanks
Perfect! You were right, I couldn't change the signature of the event handler, but a
DirectCast(e, System.Windows.Forms.HandledMouseEventArgs).Handled = True
at the end of the event worked perfectly. I *never* would have figured that out. Thanks Mike, much appreciated.
Hi,
If I understand you correctly, you just want to cancel the default behavior of the grid in response to the mouse wheel and handle it yourself.This is actually very easy to do, but there's a trick to it.
In CLR1, there was no exposed way to marked the event handled. Microsoft fixed this in CLR2, but the event definition could not be changed without breaking backward compatibility. So you probably have your MouseWheel event handler defined like so:
void ultraGrid1_MouseWheel(object sender, MouseEventArgs e)
But as long as you are using CLR2 (or higher), the actual event args passed into the event will be like this:
void ultraGrid1_MouseWheel(object sender, HandledMouseEventArgs e)
Once you do that, you can simply set e.Handled to true inside the event and the grid will skip the default handling.
EDIT: Upon further reflection... I think I might be wrong about this. You might not be able to define the event handler like I have it here. If that's the case, then what you need to do is just cast e into a HandledMouseEventArgs.