I give the user the ability to enable/disable row coloring on the fly. The backcolor is determined by a column value. However when in groupby mode I run into a problem and I have to test if a row is a group by row and that works but when the group by is 2 or three deep things get complicated. Trying to determine the best way to loop through the rows. When I encounter each sub Group should i use recursion to loop through them. Or should i use the intializeGroupby event however that only seems to look at the firstrow of each group. Also how do I get the groupby row count to use use in my for each statement. Here is some example code and example data.
=============================================
this is the initial meathod I was using a check box to turn on and off the backcoloring but one works with one sub group only.
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged Dim strStatus As String Dim iRow As Integer = 1 For Each ugrow As UltraGridRow In UltraGrid1.Rows If CheckBox1.Checked = True Then If ugrow.IsGroupByRow = False Then strStatus = ugrow.Cells("Status").Value.ToString Select Case strStatus Case "One" ugrow.Appearance.BackColor = Color.PowderBlue 'FromArgb(255, 85, 85) Case "Two" ugrow.Appearance.BackColor = Color.Pink 'FromArgb(255, 128, 128) '85, 85) Case "Three" ugrow.Appearance.BackColor = Color.Purple 'FromArgb(255, 192, 128) Case "Four" ugrow.Appearance.BackColor = Color.Orange 'FromArgb(255, 85, 85) Case "Five" ugrow.Appearance.BackColor = Color.PaleGreen 'FromArgb(255, 128, 128) '85, 85) End Select Else For Each ugChildRow As UltraGridRow In ugrow.ChildBands(0).Rows strStatus = ugChildRow.Cells("Status").Value.ToString Select Case strStatus Case "One" ugChildRow.Appearance.BackColor = Color.PowderBlue 'FromArgb(255, 85, 85) Case "Two" ugChildRow.Appearance.BackColor = Color.Pink 'FromArgb(255, 128, 128) '85, 85) Case "Three" ugChildRow.Appearance.BackColor = Color.Purple 'FromArgb(255, 192, 128) Case "Four" ugChildRow.Appearance.BackColor = Color.Orange 'FromArgb(255, 85, 85) Case "Five" ugChildRow.Appearance.BackColor = Color.PaleGreen 'FromArgb(255, 128, 128) '85, 85) End Select Next End If Else If iRow Mod 2 = 0 Then ugrow.Appearance.BackColor = Color.Gainsboro Else ugrow.Appearance.BackColor = Color.White End If iRow = iRow + 1 End If Next End Sub
=========================================================
This is the initializeGroupby event as another approch to attempt to change the backcolor. when the check box is checked i reload the grid from the dataset and this event gets fired but while it never throws an error it only seems to color the first row in each group. But yet this is ineffective.
Private Sub initGroupBy(ByVal Sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.InitializeGroupByRowEventArgs) Handles ugTestGrid.InitializeGroupByRow Dim strStatus As String If uceEnableColor.Checked = True Then If e.Row.Rows(0).IsGroupByRow = False Then Debug.Print("Row count: " & e.Row.ChildBands.Count) 'trying to get group by rows count For Each ugRow As UltraGridRow In e.Row.Rows 'trying to get group by rows count strStatus = ugRow.Cells("Status").Value.ToString Select Case strStatus Case "0ne" ugRow.Appearance.BackColor = Color.FromArgb(255, 128, 128) '85, 85) Case "Two" ugRow.Appearance.BackColor = Color.FromArgb(255, 192, 128) Case "Three" ugRow.Appearance.BackColor = Color.FromArgb(128, 128, 255) Case "Four" ugRow.Appearance.BackColor = Color.FromArgb(128, 255, 128) 'LightGreen Case "Five" ugRow.Appearance.BackColor = Color.LimeGreen 'Green End Select Next End If End If End Sub
THANKS for any help!!!
Thanks for your reply. At first I was going to say it does not work in groupby mode, but then discover you need to and a true parameter to make it recursive.
grid.Rows.Refresh(FireInitializeRow,true).
Thanks Again for you help.
Hi,
The easiest thing to do is use the IniitalizeRow event. There's no need to loop.
In order to get all the row appearances to refresh, all you have to do is call:
grid.Rows.Refresh(FireInitializeRow)