Hi,
now after hours of searching I can't find a way to scroll an activ row to the center of the grid.
With arrowkeys I navigate through all cells, when pressing ENTER I let the grid sorting the appropiate column and "yes I can" scroll "ScrollRowIntoView".
ultraGrid1.ActiveRowScrollRegion.ScrollRowIntoView(ultraGrid1.ActiveRow);
But I can't scroll to the center of the grid.
Are there any samples or methods to do this?
Thx Nobbi
Hello Nobbi,
If you would like the ActiveRow to be in the middle of the visible window you could try setting it like the following:
private void ultraButton1_Click(object sender, EventArgs e) { int i = (int)Math.Floor((double)ultraGrid1.DisplayLayout.RowScrollRegions[0].VisibleRows.Count / 2); ultraGrid1.Rows[ultraGrid1.DisplayLayout.RowScrollRegions[0].FirstRow.Index + i-1].Activate(); }
If you would like to scroll the UltraGrid only you should determine what exactly would have to happen using something like the following:
ultraGrid1.DisplayLayout.RowScrollRegions[0].Scroll(Infragistics.Win.UltraWinGrid.RowScrollAction.LineDown); ultraGrid1.DisplayLayout.RowScrollRegions[0].ScrollPosition = determine where the scroll bar should be;
Please feel free to let me know if I missunderstood what you are asking here.
Hello Danko,
the first code comes close to that I'm looking for. Unfortunately it's not the active Row which is scrolled to the middle of the visble window. And afterwards I have the Rowselection activated, so I lost the focus of the certain cell.
I try to explain again.
I navigate with the arrowkeys through different Cells (up and down, right and left). When pressing ENTER the Grid sorts the column of the activated cell. Then I can make the still activated Cell visible. But the activated cell is generally not in the middle of the visible window of the grid. So I need code, which scrolls the activerow belonging to that cell to be in the middle of the grid (and not loosing the focus of my cell).
Please excuse my english
Greetings from Germany
Nobbi
Hi Nobbi,
There's no method in the grid to scroll a row into the exact middle. The only way to scroll to a specific position in the grid it so set the FirstRow property of the ActiveRowScrollRegion. So if you know what row you want to be in the middle and you know how many rows fit in the grid's display, you could find a row that is a few rows up from the one you want in the middle and make it the FirstRow. But how you do this will depend on lot on other factors and assumptions you can make in your application.
For example, if the row in question is the first row in the grid, then you cannot scroll it to the middle.
Here's some quick sample code I whipped up. It is by no means complete - it does not handle every case, but it should point you in the right direction.
private void ScrollRowToMiddle(UltraGridRow row) { UltraGrid grid = (UltraGrid)row.Band.Layout.Grid; UIElement gridElement = grid.DisplayLayout.UIElement; if (gridElement == null) return; UIElement rowColRegionIntersectionUIElement = gridElement.GetDescendant(typeof(RowColRegionIntersectionUIElement)); if (rowColRegionIntersectionUIElement == null) return; // Determine the total number of rows that can fit in the visible // area of the grid. We are assuming that the Rows are all the same height. int visibleRows = rowColRegionIntersectionUIElement.Rect.Height / row.Height; // Find the row that is half the visibleRows prior to the row we want. // UltraGridRow newFirstRow = row; int rowOffset = visibleRows / 2; for (int i = 0; i < rowOffset; i++) { if (newFirstRow.HasPrevSibling(false, true)) newFirstRow = newFirstRow.GetSibling(SiblingRow.Previous, false, true); } // Set the new FirstRow. grid.ActiveRowScrollRegion.FirstRow = newFirstRow; }