Conditional Styling RowType.CaptionCoveredRow

Hi, I need to be able to change the back colour of the caption covered row when grouping based on the hex colour that is presented into the 4th column of the sfdatagrid. All the rows for each grouping will have the same hex colour stored in column 4.

I have tried the folloing but it obviously doesnt work:

    Private Sub sfd_Bundle_DrawCell(sender As Object, e As DrawCellEventArgs) Handles sfd_Bundle.DrawCell
        If e.DataRow.RowType = RowType.CaptionCoveredRow Then
            e.Style.BackColor = ColorTranslator.FromHtml(e.DataRow.RowData(3).ToString)
        End If
    End Sub

Please could you assist?

Thanks, Martin

5 Replies

VS Vijayarasan Sivanandham Syncfusion Team June 4, 2020 02:10 PM UTC

Hi Martin,

Thank you for contacting Syncfusion support.

Your requirement can be achieved by using Key value of grouped column in SfDataGrid. Please refer the below code snippet,
 
AddHandler Me.sfDataGrid.DrawCell, AddressOf SfDataGrid_DrawCell 
 
Private Sub SfDataGrid_DrawCell(ByVal sender As Object, ByVal e As Syncfusion.WinForms.DataGrid.Events.DrawCellEventArgs) 
                If e.DataRow.RowType = RowType.CaptionCoveredRow Then 
                                Dim Key = (TryCast(e.DataRow.RowData, Group)).Key 
                                e.Style.BackColor = ColorTranslator.FromHtml(Key.ToString()) 
                End If 
End Sub 
Regards,
Vijayarasan S
 



MA Martin replied to Vijayarasan Sivanandham June 5, 2020 08:53 AM UTC

Hi Martin,

Thank you for contacting Syncfusion support.

Your requirement can be achieved by using Key value of grouped column in SfDataGrid. Please refer the below code snippet,
 
AddHandler Me.sfDataGrid.DrawCell, AddressOf SfDataGrid_DrawCell 
 
Private Sub SfDataGrid_DrawCell(ByVal sender As Object, ByVal e As Syncfusion.WinForms.DataGrid.Events.DrawCellEventArgs) 
                If e.DataRow.RowType = RowType.CaptionCoveredRow Then 
                                Dim Key = (TryCast(e.DataRow.RowData, Group)).Key 
                                e.Style.BackColor = ColorTranslator.FromHtml(Key.ToString()) 
                End If 
End Sub 
Regards,
Vijayarasan S
 


Thank you for the reponse Vijayarasan. The HEX column is not one i am grouping by so this doesnt work, the hex column contains the same data for each row in that grouping. By referencing the key I could always query the DB for that hex colour if there is no way of referencing another column when drawing the caption covered row.


VS Vijayarasan Sivanandham Syncfusion Team June 8, 2020 01:10 PM UTC

Hi Martin,

Thanks for the update.

 
In above mentioned image contains grouped other columns in SfDataGrid. In this case Group contains more than one value of HeaxColor values. So, which  HexaColor value you need to apply in CaptionSummaryCoveredRow. Can you please provide the more details related to your query?

Regards,
Vijayarasan S 



MA Martin replied to Vijayarasan Sivanandham June 9, 2020 02:27 PM UTC

Hi Martin,

Thanks for the update.

 
In above mentioned image contains grouped other columns in SfDataGrid. In this case Group contains more than one value of HeaxColor values. So, which  HexaColor value you need to apply in CaptionSummaryCoveredRow. Can you please provide the more details related to your query?

Regards,
Vijayarasan S 


Hi Vijayarasan,

The Hex value is idential for every row in each grouping. If there is a siple way to access this value that woudl be great, but in the emantime i have constructed a simple function that retrieves the hex value based on the grouping key:

    Private Sub sfd_Bundle_DrawCell(sender As Object, e As DrawCellEventArgs) Handles sfd_Bundle.DrawCell
        If e.DataRow.RowType = RowType.CaptionCoveredRow Then
            Dim Key = (TryCast(e.DataRow.RowData, Group)).Key
            e.Style.BackColor = ColorTranslator.FromHtml(GroupingColour(Key.ToString()))
        End If
    End Sub

    Public Function GroupingColour(ByVal SectionDescription As String)
        Dim hex As String
        Dim result() As System.Data.DataRow = SectionCollection.Select("Description = '" & SectionDescription & "'")

        For Each row As System.Data.DataRow In result
            hex = row(2).ToString
        Next
        Return hex
    End Function


VS Vijayarasan Sivanandham Syncfusion Team June 10, 2020 08:31 AM UTC

Hi Martin,

Thanks for the update.

We are glad to know that the reported issue has been resolved. Please get back to us if you have any other queries. As always, we will happy to assist you
😊

Regards,
Vijayarasan S



Loader.
Up arrow icon