RowStyle colors one single cell?

Hi!

I'm using the following code to change the entire line color of a SFDataGrid:


Private Sub gridArquivos_QueryRowStyle(sender As Object, e As QueryRowStyleEventArgs) Handles gridArquivos.QueryRowStyle

Try

If e.RowType = RowType.DefaultRow Then
Dim dataRowView = TryCast(e.RowData, DadosResultados)
If dataRowView IsNot Nothing Then
Dim dataRow = dataRowView.Detalhes
If (dataRow IsNot "-") AndAlso (dataRow IsNot "") Then
e.Style.BackColor = Color.OrangeRed
e.Style.TextColor = Color.Yellow
End If
End If
End If

Catch ex As Exception

End Try
     End Sub


DadosResultados is a structure which holds all fields of an unbound table.
Everything goes OK but only the current cell has its color changes (the column Detalhes).
Why does not the entire line change its background color?

I appreciate any help.
Kind regards,
David


14 Replies 1 reply marked as answer

MA Mohanram Anbukkarasu Syncfusion Team August 31, 2020 02:14 PM UTC

Hi David,  

Thanks for contacting Syncfusion support.  

We are little unclear with the reported issue. We have prepared a sample using the provided code snippets but we are unable to found any issue in applying the colors for the rows. The sample we have used to check the reported issue is available in the following link for your reference.  


Please have a look at this sample and let us know if we have missed any customization you have done in your application or try to reproduce the reported issue in this sample and revert to us with the modified sample and the image illustration of the reported issue. It will be more helpful for us to find the exact cause for the issue and to provide a prompt solution at earlier.  

Regards,  
Mohanram A. 



DA DavidBS August 31, 2020 05:24 PM UTC

Hi Monharam.

Yes, it seems I'm using a specific settings in THEMES or something else that is causing the weird behavior. See my image and check what I'm getting here with the above code.

Notice that I had already checked each property of the colored column against the non-colored columns and I couldn't see any difference...

I will perform a deep analysis in your code, comparing with the mine.

Thank you very much.


Attachment: Aug31_2c2e41eb.zip


MA Mohanram Anbukkarasu Syncfusion Team September 1, 2020 02:45 PM UTC

Hi David, 

Thanks for the update.  

We will wait to hear from you. 

Regards, 
Mohanram A. 



DA DavidBS September 2, 2020 05:12 PM UTC

Dear Mohanram,

I set your code (with what I'm doing here) to your analysis.

In this code you will be able to see and reproduce the problem - I guess it is related to custom colors in cells, even if they're set only once, in the LOAD event and before the Handler deviation.

Please, see the LOAD event (the call for SetGridColor function).

I'll be forward for your comments and a (possible) solution.

Kind regards,
David


Attachment: SfDataGrid_WinForms_VB_d0e5ad93.zip


VS Vijayarasan Sivanandham Syncfusion Team September 3, 2020 01:53 PM UTC

Hi DavidBS,

Thanks for the update

Based on provided information You are setting the GridCellStyle in SetGridColor function and After applying the RowStyle by using QueryRowStyle event. This not an issue as per our SfDataGrid architecture GridColumn.CellStyle has higher priority than RowStyle. So, RowStyle not applied in your application. This is behavior of our SfDataGrid control.

Please let us know, if you require further assistance on this.

Regards,
Vijayarasan S 



DA DavidBS September 3, 2020 05:39 PM UTC

Hi Vijayarasan,

Thank you for your answer; I understood your point.

My application has "themes" to change colors of the entire interface. Would you suggest a way to perform the same color-change but without the Cell-Style procedure?

Performance is also a key of the application and set the RowStyle for each grid new line is not an option, since I perform the cell-style once and in a global scope.

Any suggestion?

Thank you very much for your answer.
Kindest regards, 
David


MA Mohanram Anbukkarasu Syncfusion Team September 4, 2020 01:03 PM UTC

Hi David, 

Thanks for the update. 

We are little unclear in your requirement and why you are trying to change color using both CellStyle and QueryRowStyle event. You an change the color for the  cells in the DataGrid either by CellStyle (SfDataGrid.Style.CellStyle or GridColumn.CellStyle) or by using QueryRowStyle and QueryCellStyle events. 

Kindly revert to us with more details about your requirement with some illustrations for better understanding, if the provided solutions doesn’t meet your requirement. It will be more helpful for us to provide a prompt solution without further delay.  

Regards, 
Mohanram A. 



DA DavidBS September 4, 2020 02:29 PM UTC

Hi Monharam!

It´s easy to understand:

1- The application has "night/day" themes in its configuration and once user choose one, we set everything accordingly.

2- The grid does not work on a database - it's fulfiled with random-and-realtime data of processing files during one of its functions. In other words, my grid starts "empty".

3- In the form load event, we set the colors of the UI accordingly the current there. But, since all windows are "thread-safe", user can open and change the theme configuration at any time - even with this specific grid windows already opened. Because of this, a function is called everytime user changes themes (night/day) and set the grid colors using the code I sent to you.

4- Why RowEvent? Because due to an evetual ERROR in any file, I try to call the user's attention to the specific file/row, changing its color do "yellow on red".

Really, I don't know exactly why I do change only some columns and other don't - maybe I have had problems during some specific processing of colors in some point of the program (it has several months). It explains why DETAILS column change its color on RowEvent (it is NOT set neither at the LOAD event nor in the mentioned function above) and the others, don't.

In fact, I need only:

1- set the grid colors and font colors due to specific themes of the application, anytime, even with the grid empty or filled.
2- set the color of an specific line (or its columns) whenever an error is raised on any file, described into that specific line.

Thank you very much for the whole attention.

Kindest regards,
David





MA Mohanram Anbukkarasu Syncfusion Team September 7, 2020 11:18 AM UTC

Hi David, 

Thanks for the update.  

From your update it is clear that your requirement is to display all the rows in a same color initially and need to change the color of any specific row when some change occurs in the row (error raised on any file ). 

The only way to achieve this is to use QueryRowStyle event. You should add conditions to color the color for the normal row and a row where error raised as shown in the following code example.  

Code example :  

Private Sub SfDataGrid1_QueryRowStyle(ByVal sender As Object, ByVal e As Syncfusion.WinForms.DataGrid.Events.QueryRowStyleEventArgs) 
       If e.RowType = RowType.DefaultRow Then 
              Dim dataRowView = TryCast(e.RowData, OrderInfo) 
              If dataRowView IsNot Nothing Then 
                     Dim dataRow = dataRowView.CustomerID 
            If dataRow IsNot "-" AndAlso dataRow IsNot "" Then 
                e.Style.BackColor = Color.OrangeRed 
                e.Style.TextColor = Color.Yellow 
            Else 
                e.Style.BackColor = Cor_Fundo 
                e.Style.TextColor = Cor_ProgressFonte 
            End If 
              End If 
       End If 
End Sub 


Please let us know if you require any other assistance from us. 

Regards, 
Mohanram A. 


Marked as answer

DA DavidBS September 7, 2020 12:28 PM UTC

Hi Monharam,

I got it. I'll try your solution and come back to status.

Thank you.


DA DavidBS September 7, 2020 07:57 PM UTC

Hi Monharam!

Yes, using the suggested code is the right solution and I could set the first, second and third columns with it.

BUT, if we utilize a column set as "checkbox" (since it has the own CellStyle, I guess), the QueryRowStyle is ineffective - and I guess that just because of I had been seting these column-styles manually.

Any sugestion?

I appreciate for your efforts in help me.





Attachment: set7_6d55eac5.zip


MA Mohanram Anbukkarasu Syncfusion Team September 8, 2020 11:17 AM UTC

Hi David, 

Thanks for the update.  

QueryRowStyle event will set style for the CheckBox column also same as other columns. From the provided image it seems that you have set CellStyle property for the check box columns. As you mentioned, If you set CellStyle for the checkbox columns manually, then the QueryRowStyle event will have no effect on those columns. 

Please let us know if you require any other assistance from us.  

Regards, 
Mohanram A. 



DA DavidBS September 8, 2020 11:32 AM UTC

Hi Mohanram,

I set the "chekbox" itself style (tick color and border color) using the Property page available at design time.
But its BACKCOLOR is not set ...

Anyway, I will revise my code.
Thank you very much Mohanram for the whole attention.

Kindest regards,
David



MA Mohanram Anbukkarasu Syncfusion Team September 9, 2020 12:50 PM UTC

Hi David, 

Thanks for the update. 

We are glad to know that the reported problem has been resolved at your end. Please let us know if you have any further queries on this. We are happy to help you. 

Regards, 
Mohanram A. 


Loader.
Up arrow icon