Home Forums WinForms controls Xceed Grid for WinForms Coloring Alternating Sorted Groups….How?

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #14068 |

    Here’s my current coloring routine:

    Private Sub ColorGridGroups(ByVal grid As GridControl)
    Dim Toggle As Boolean = False
    For Each myGroup As Group In grid.Groups
    Toggle = (Toggle = False)
    If Toggle Then
    myGroup.BackColor = Color.Beige
    End If
    Next
    End Sub

    The problem is this: The groups are built dynamically and are getting placed into the Groups collection in the order of creation – but VISUALLY they are sorted (ascending) so the above loop does not produce the desired result which would be “Alternating group colors.”

    Is there anyway to loop the Groups collection in a sorted manner? Or alternately is there a method like, GetSortedGroups that I’m not seeing?

    I’m looking for a convenient method, not the grunt method which would be capturing the Title of the group into an arraylist along with their indexes, sorting the arraylist and then looping through that sort.

    Thanks all!

    -LK

    Imported from legacy forums. Posted by Curtis (had 2344 views)

    User (Old forums)
    Member
    Post count: 23064

    Try this (untested code):<pre>Dim toggle As Boolean = False
    Dim row As Xceed.Grid.DataRow
    Dim group As Xceed.Grid.GroupBase = Nothing
    For Each row in grid.GetSortedDataRows(True) Do
    If row.ParentGroup <> group Then
    group = row.ParentGroup
    toggle = Not toggle
    If toggle Then
    group.BackColor = Color.Beige
    End If
    End If
    Next</pre>

    Imported from legacy forums. Posted by Tommy (had 349 views)

    User (Old forums)
    Member
    Post count: 23064

    I almost half expected a reply from you Tommy 🙂 Thanks for the input, it’s appreciated.

    Unfortunately, my DataRows are sorted differently than the Groups – so this would also produce unwanted results.

    I think for the time, I’ll just stick to the grunt method! It’s clunky but fast and works.

    Thanks again 🙂

    Kindest regards,
    Curtis

    Imported from legacy forums. Posted by Curtis (had 3409 views)

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.