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 mike, I found issue but the thing is now when I make last partial row invisible at that time that portion is empty which really looks dirty.
Is there any way I can handle that area?
Mike,
Thanks for your reply.
As you mentioned I comment this lines of code and now only last partial visible row is not visible. Thanks for your help. but we are using this code to create a header checkbox to select all rows in grid. So now when I comment this code I am not able to create header checkbox. Can you please let me know which line in this code has issue?
If TypeOf parent Is HeaderUIElement Then
' ' Get the actual ColumnHeader that the HeaderUIElement is attached to
' Dim aColHeader As ColumnHeader
' aColHeader = CType(parent, HeaderUIElement).Header
' ' Only put the Checkbox in the header of the Boolean columns
' If aColHeader.Column.Key = oKey Then
' Dim aTextUIElement As TextUIElement
' Dim aCheckBoxUIElement As CheckBoxUIElement
' ' Since the grid sometimes re-uses UIElements, we need to check to make sure
' ' the header does not already have a CheckBoxUIElement attached to it.
' ' If it does, we just get a reference to the existing CheckBoxUIElement,
' ' and reset its properties.
' aCheckBoxUIElement = parent.GetDescendant(GetType(CheckBoxUIElement))
' If aCheckBoxUIElement Is Nothing Then
' ' Create a New CheckBoxUIElement
' aCheckBoxUIElement = New CheckBoxUIElement(parent)
' End If
' ' Get the TextUIElement - this is where the text for the
' ' Header is displayed. We need this so we can push it to the right
' ' in order to make room for the CheckBox
' aTextUIElement = CType(parent.GetDescendant(GetType(TextUIElement)), TextUIElement)
' ' Sanity check
' If aTextUIElement Is Nothing Then Exit Sub
' ' Get the Header and see if the Tag has been set. I the Tag is
' ' set, we will assume it's the stored CheckState. This has to be
' ' done in order to maintain the CheckState when the grid repaints and
' ' UIElement are destroyed and recreated.
' Dim aHeader As ColumnHeader = CType(aCheckBoxUIElement.GetAncestor(GetType(HeaderUIElement)).GetContext(GetType(ColumnHeader)), ColumnHeader)
' If aHeader.Tag Is Nothing Then
' ' If the tag was nothing, this is probably the first time this
' ' HeaderRow is being displayed, so default to Indeterminate
' 'aHeader.Tag = Windows.Forms.CheckState.Indeterminate
' If oCheckState Then
' aHeader.Tag = Windows.Forms.CheckState.Indeterminate
' Else
' aHeader.Tag = oCheckState
' aCheckBoxUIElement.CheckState = CType(aHeader.Tag, Windows.Forms.CheckState)
' ' Hook the ElementClick of the CheckBoxUIElement
' AddHandler aCheckBoxUIElement.ElementClick, AddressOf aCheckBoxUIElement_ElementClick
' ' Add the CheckBoxUIElement to the HeaderUIElement
' parent.ChildElements.Add(aCheckBoxUIElement)
' ' Position the CheckBoxUIElement. The number 3 here is used for 3
' ' pixels of padding between the CheckBox and the side of the header
' ' The CheckBox is shifted down slightly so it is centered in the header
' aCheckBoxUIElement.Rect = New System.Drawing.Rectangle(parent.Rect.X + 6, parent.Rect.Y + ((parent.Rect.Height - aCheckBoxUIElement.CheckSize.Height) / 2), aCheckBoxUIElement.CheckSize.Width, aCheckBoxUIElement.CheckSize.Height)
' ' Push the TextUIElement to the right a little to make
' ' room for the CheckBox. 3 pixels of padding are used again.
' aTextUIElement.Rect = New System.Drawing.Rectangle(aCheckBoxUIElement.Rect.Right + 3, aTextUIElement.Rect.Y, parent.Rect.Width - (aCheckBoxUIElement.Rect.Right - parent.Rect.X), aTextUIElement.Rect.Height)
' ' If the column is not a boolean column, we do not want to have a checkbox in it
' ' Since UIElements can be reused by the grid, there is a chance that one of the
' ' HeaderUIElements that we added a checkbox to for a boolean column header
' ' will be reused in a column that is not boolean. In this case, we must remove
' ' the checkbox so that it will not appear in an inappropriate column header.
' If Not aCheckBoxUIElement Is Nothing Then
' parent.ChildElements.Remove(aCheckBoxUIElement)
' aCheckBoxUIElement.Dispose()
End If
It's tough to tell much from a code snippet like this. But this looks like it's the code from the CreationFilter. Are you saying that this scrolling only happens when you have the CreationFilter in place? I thought the point of the CreationFilter was to prevent the unwanted scrolling.
Mike thanks for your reply. Here is my code. I will try to reproduce it in sample project.
Public Sub AfterCreateChildElements(ByVal parent As Infragistics.Win.UIElement) Implements Infragistics.Win.IUIElementCreationFilter.AfterCreateChildElements
' Check for the HeaderUIElement
' Get the actual ColumnHeader that the HeaderUIElement is attached to
Dim aColHeader As ColumnHeader
aColHeader = CType(parent, HeaderUIElement).Header
' Only put the Checkbox in the header of the Boolean columns
If aColHeader.Column.Key = oKey Then
Dim aTextUIElement As TextUIElement
Dim aCheckBoxUIElement As CheckBoxUIElement
' Since the grid sometimes re-uses UIElements, we need to check to make sure
' the header does not already have a CheckBoxUIElement attached to it.
' If it does, we just get a reference to the existing CheckBoxUIElement,
' and reset its properties.
aCheckBoxUIElement = parent.GetDescendant(GetType(CheckBoxUIElement))
If aCheckBoxUIElement Is Nothing Then
' Create a New CheckBoxUIElement
aCheckBoxUIElement = New CheckBoxUIElement(parent)
' Get the TextUIElement - this is where the text for the
' Header is displayed. We need this so we can push it to the right
' in order to make room for the CheckBox
aTextUIElement = CType(parent.GetDescendant(GetType(TextUIElement)), TextUIElement)
' Sanity check
If aTextUIElement Is Nothing Then Exit Sub
' Get the Header and see if the Tag has been set. I the Tag is
' set, we will assume it's the stored CheckState. This has to be
' done in order to maintain the CheckState when the grid repaints and
' UIElement are destroyed and recreated.
Dim aHeader As ColumnHeader = CType(aCheckBoxUIElement.GetAncestor(GetType(HeaderUIElement)).GetContext(GetType(ColumnHeader)), ColumnHeader)
If aHeader.Tag Is Nothing Then
' If the tag was nothing, this is probably the first time this
' HeaderRow is being displayed, so default to Indeterminate
'aHeader.Tag = Windows.Forms.CheckState.Indeterminate
If oCheckState Then
aHeader.Tag = Windows.Forms.CheckState.Indeterminate
Else
aHeader.Tag = oCheckState
aCheckBoxUIElement.CheckState = CType(aHeader.Tag, Windows.Forms.CheckState)
' Hook the ElementClick of the CheckBoxUIElement
AddHandler aCheckBoxUIElement.ElementClick, AddressOf aCheckBoxUIElement_ElementClick
' Add the CheckBoxUIElement to the HeaderUIElement
parent.ChildElements.Add(aCheckBoxUIElement)
' Position the CheckBoxUIElement. The number 3 here is used for 3
' pixels of padding between the CheckBox and the side of the header
' The CheckBox is shifted down slightly so it is centered in the header
aCheckBoxUIElement.Rect = New System.Drawing.Rectangle(parent.Rect.X + 6, parent.Rect.Y + ((parent.Rect.Height - aCheckBoxUIElement.CheckSize.Height) / 2), aCheckBoxUIElement.CheckSize.Width, aCheckBoxUIElement.CheckSize.Height)
' Push the TextUIElement to the right a little to make
' room for the CheckBox. 3 pixels of padding are used again.
aTextUIElement.Rect = New System.Drawing.Rectangle(aCheckBoxUIElement.Rect.Right + 3, aTextUIElement.Rect.Y, parent.Rect.Width - (aCheckBoxUIElement.Rect.Right - parent.Rect.X), aTextUIElement.Rect.Height)
' If the column is not a boolean column, we do not want to have a checkbox in it
' Since UIElements can be reused by the grid, there is a chance that one of the
' HeaderUIElements that we added a checkbox to for a boolean column header
' will be reused in a column that is not boolean. In this case, we must remove
' the checkbox so that it will not appear in an inappropriate column header.
If Not aCheckBoxUIElement Is Nothing Then
parent.ChildElements.Remove(aCheckBoxUIElement)
aCheckBoxUIElement.Dispose()
If TypeOf parent Is RowColRegionIntersectionUIElement Then
' 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.
Dim elementsToRemove As New List(Of UIElement)()
' Loop through the child elements.
For Each element As UIElement In parent.ChildElements
' Check for RowUIElements. We don't care about any other type here,
' so if it's not a RowUIElement, skip it.
Dim rowUIElement As RowUIElement = TryCast(element, RowUIElement)
If rowUIElement Is Nothing Then
Continue For
' Check to see if the RowUIElement extends beyond the bottom of the parent.
If rowUIElement.Rect.Bottom > parent.Rect.Bottom - 20 Then
' 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)
Next
' Remove all of the elements we marked for removal.
For Each element As UIElement In elementsToRemove
parent.ChildElements.Remove(element)
End Sub
Public Function BeforeCreateChildElements(ByVal parent As Infragistics.Win.UIElement) As Boolean Implements Infragistics.Win.IUIElementCreationFilter.BeforeCreateChildElements
' Don't need to do anything here.
Return False
End Function
Private Sub aCheckBoxUIElement_ElementClick(ByVal sender As Object, ByVal e As Infragistics.Win.UIElementEventArgs)
' Get the CheckBoxUIElement that was clicked
Dim aCheckBoxUIElement As CheckBoxUIElement = CType(e.Element, CheckBoxUIElement)
' Get the Header associated with this particular element
Dim aHeaderUIElement As HeaderUIElement = CType(aCheckBoxUIElement.GetAncestor(GetType(HeaderUIElement)), HeaderUIElement)
Dim aHeader As ColumnHeader = CType(aHeaderUIElement.GetContext(GetType(ColumnHeader)), ColumnHeader)
' Set the Tag on the Header to the new CheckState
aHeader.Tag = aCheckBoxUIElement.CheckState
' So that we can apply various changes only to the relevant Rows collection that the header belongs to
Dim hRows As RowsCollection = CType(aHeaderUIElement.GetContext(GetType(RowsCollection)), RowsCollection)
' Raise an event so the programmer can do something when the CheckState changes
RaiseEvent HeaderCheckBoxClicked(Me, New HeaderCheckBoxEventArgs(aHeader, aCheckBoxUIElement.CheckState, hRows))
If the row is completely visible and clicking on that row is causing the grid to scroll, then something in your code must be causing that. There's no reason why the grid would scroll a row that is already in view. You might want to search your code for references the ActiveRowScrollRegion or the RowScrollRegions collection to see if you are referencing these in order to force the grid to scroll for some reason.
If you can post a small sample project that demonstrates this behavior, I'd be happy to take a look and find out why it's happening.