Hi and thanks for reading my question,
I have a UltraWinGrid with a large number of rows, let's say more than 100. On the screen at a given time there are visible only about 7, 8 of them. I'm looking for a way of showing only the rows that are fully visible, so if the last row is not completely visible it should not be visible until the grid is scrolled.
I've searched for a property or for a method of doing this. It can easily be done for columns but i haven't found a way to do it for rows. Also in this case resizing the grid is not an option.
Thanks for any tips,
Adrian Faciu.
Hi Adrian,
So basically, you don't want the grid to show any partially-visible rows?
You would have to use a CreationFilter for this. Here's some quick code I whipped up which seems to work pretty well:
public class HidePartialRows_CreationFilter : IUIElementCreationFilter { #region IUIElementCreationFilter Members void IUIElementCreationFilter.AfterCreateChildElements(UIElement parent) { // Check for the RowColRegionIntersectionUIElement. This is the element // that contains the RowUIElements (and possibly other things). if (parent is RowColRegionIntersectionUIElement) { // Keep a list of elements that we want to remove. We will probably // only have one element in the list, but it doesn't hurt to be extra careful. List<UIElement> elementsToRemove = new List<UIElement>(); // Loop through the child elements. foreach (UIElement element in parent.ChildElements) { // Check for RowUIElements. We don't care about any other type here, // so if it's not a RowUIElement, skip it. RowUIElement rowUIElement = element as RowUIElement; if (rowUIElement == null) continue; // Check to see if the RowUIElement extends beyond the bottom of the parent. if (rowUIElement.Rect.Bottom > parent.Rect.Bottom) { // This Row is clipped, so add it to the list of elements to remove. // We don't want to remove the element here directly, because that // would modify the contents of the ChildElements collection, and we // are currently in a ForEach loop on that collection so it's a bad idea. elementsToRemove.Add(element); } } // Remove all of the elements we marked for removal. foreach (UIElement element in elementsToRemove) { parent.ChildElements.Remove(element); } } } // Do nothing bool IUIElementCreationFilter.BeforeCreateChildElements(UIElement parent) { return false; } #endregion }
Mike it's really helpful code. i am able to remove last partial row but still i have an issue last visible row when i am trying to click on it , it steps up and put focus on next one. is there any way i can hide last two rows one is partial visible and one visible?
OK let me think for a button or message.
But still issue is that even when i click last fully visible row as was attached in screenshot still it moves up.
Yes, that was the point of my sample code - since the partial row is not visible, it alleviates the problem with clicking on that row and having it scroll into view. You have to explicitly scroll the row into view and then click it, so there's no weird mouse behavior, like clicking on a row and having that row move so that there's a different row under the mouse when you release the mouse button.
It looks like maybe Georgi's code was intended to stretch the last fully-visible row so that it fills the available space. Seems like a bizarre UI to me, but it that's what you want you could extend the UIElements in the last visible row. You can't change the Height property on the row inside a CreationFilter - that's a bad idea.
Another option would be to create some other element and put it into that gap - like a message or a button that you could click to scroll the next row into view. But that's problematic, because the height of the gap can vary and there might not be enough room for any other elements.
Thanks for your reply.
This sample project was given by Georgi to set height of row. now i am using a code which is given by you.
I attach a screenshot how it looks.
The last partial visible row is hidden but it's a blank row over there means there is noting in that area.
Hi,
The code you are using in this sample isn't anything like the code I posted. One big problem with this code is that you are setting the Height property on the row inside of the CreationFilter. You should not do that, as this will dirty the grid elements and cause the CreationFilter to fire again in an infinite loop.
The code I posted just hides the last row if it is cut off. Why are you resizing the rows?
Mike,
Here is your sample where i made this change.
(rowUIElement.Rect.Bottom >= parent.Rect.Bottom)
You can see now how it behaves.