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?
Hi Mike,
I am on same page where i was stared to make this change. Here is my issue.
I am trying to use same code as you mentioned. last partial row is visible now but still clicking on last visible rows it moves next row and i have a hyperlink in my grid.
Can you please let me know some solution?
Hi,
I'm not sure I understand you. You are saying that you are using the code I posted here, and that somehow, clicking on a blank area where there is no visible row displayed is causing the grid to scroll? I don't see how that's possible.
I tried it out and clicking on the empty space does not scroll the grid on my machine.
Thanks for your reply.
When I am trying to click on last fully visible row still it moves row up and selects next one.
I don't have any blank area on grid.
My guess is that the row is not fully visible, then. Maybe there is one pixel cut off? I suppose it's possible that the logic in the CreationFilter I created here is off by a pixel.
Try changing:
if (rowUIElement.Rect.Bottom > parent.Rect.Bottom)to if (rowUIElement.Rect.Bottom >= parent.Rect.Bottom)Or maybe add one to fudge it a little.
Still it's not working for me. but i found this code while i was doing some research.
but there are some properties which is not in infragistics . can we do make same code like this in infragistics.
It's simple and easy to understand.
if (!this.dataGridView1.CurrentCell.Displayed)
{ Console.WriteLine("current cell is not displayed");}else{ Rectangle displayCellRect = this.dataGridView1.GetCellDisplayRectangle(this.dataGridView1.CurrentCell.ColumnIndex, this.dataGridView1.CurrentCell.RowIndex, true); if (displayCellRect.Width == this.dataGridView1.Columns[this.dataGridView1.CurrentCell.ColumnIndex].Width) { Console.WriteLine("current cell is completely displayed"); } else { Console.WriteLine("current cell is partially displayed"); } }
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.
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.
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.