This is a migrated thread and some comments may be shown as answers.

Override pinned columns color with the RowFormatting event

6 Answers 233 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Cernat
Top achievements
Rank 1
Cernat asked on 14 Dec 2016, 08:00 AM

Hello!

Why does RowFormating event does not override the color for the pinned columns?

It only formats the unpinned columns of the GridView. The RowFormatting code bellow.

Can someone point me in the right direction?

Thank you very much!

Private Sub RadGridView1_RowFormatting(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.RowFormattingEventArgs) Handles RadGridView1.RowFormatting
 
        If e.RowElement.RowInfo.Cells("Status").Value = "Finalizata" Then
            e.RowElement.DrawFill = True
            e.RowElement.GradientStyle = Telerik.WinControls.GradientStyles.Solid
            e.RowElement.BackColor = Color.DimGray
        Else
            e.RowElement.ResetValue(LightVisualElement.BackColorProperty, Telerik.WinControls.ValueResetFlags.Local)
            e.RowElement.ResetValue(LightVisualElement.GradientStyleProperty, Telerik.WinControls.ValueResetFlags.Local)
            e.RowElement.ResetValue(LightVisualElement.DrawFillProperty, Telerik.WinControls.ValueResetFlags.Local)
        End If
    End Sub

 

6 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 14 Dec 2016, 01:40 PM
Hello Cernat,

Thank you for writing.  

Depending on the specific theme, RadGridView's style may be applied the row or cell level. For the pinned rows in ControlDefault theme, it is applied at the cell level. That is why in order to achieve the desired style, it is suitable to use the CellFormatting event:  
Private Sub RadGridView1_CellFormatting(sender As Object, e As CellFormattingEventArgs) Handles RadGridView1.CellFormatting
    If (e.CellElement.RowInfo.Cells("Name").Value & "").Contains("1") Then
        e.CellElement.DrawFill = True
        e.CellElement.GradientStyle = Telerik.WinControls.GradientStyles.Solid
        e.CellElement.BackColor = Color.DimGray
    Else
        e.CellElement.ResetValue(LightVisualElement.BackColorProperty, Telerik.WinControls.ValueResetFlags.Local)
        e.CellElement.ResetValue(LightVisualElement.GradientStyleProperty, Telerik.WinControls.ValueResetFlags.Local)
        e.CellElement.ResetValue(LightVisualElement.DrawFillProperty, Telerik.WinControls.ValueResetFlags.Local)
    End If
End Sub

I hope this information helps. Should you have further questions I would be glad to help.

Regards,
Dess
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Cernat
Top achievements
Rank 1
answered on 14 Dec 2016, 02:02 PM

Hello! Thanks for answering. The CellFormatting event fires for another rules that I setup. Below the code from the event. How can I squeeze the painting of the row in gray if cell value of Status column = "Finalizata"? Cant figure it out.

 

Private Sub RadGridView1_CellFormatting2(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.CellFormattingEventArgs) Handles RadGridView1.CellFormatting
       If e.CellElement.ColumnInfo.HeaderText = "Intarziere" Then
           If e.CellElement.RowInfo.Cells("Diferenta").Value + 5 > 0 Then
               e.CellElement.DrawFill = True
               e.CellElement.ForeColor = Color.White
               e.CellElement.NumberOfColors = 1
               e.CellElement.BackColor = Color.Red
           Else
               e.CellElement.DrawFill = True
               e.CellElement.ForeColor = Color.Black
               e.CellElement.NumberOfColors = 1
               e.CellElement.BackColor = Color.LightGreen
           End If
       Else
           e.CellElement.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local)
           e.CellElement.ResetValue(LightVisualElement.ForeColorProperty, ValueResetFlags.Local)
           e.CellElement.ResetValue(LightVisualElement.NumberOfColorsProperty, ValueResetFlags.Local)
           e.CellElement.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local)
       End If
   End Sub
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 15 Dec 2016, 01:25 PM
Hello Cernat, 

Thank you for writing back. 

It is necessary to combine the different formatting rules in different "if" statements. However, don't forget to reset the applied settings in the default "else" clause in order to avoid applying incorrect styles to the other cells. In other words, each "if" statement that applies a certain style should have an "else" clause for resetting the options or applying some other style. Here is a sample code snippet which result is illustrated in the attached screenshot:

Note that this is just a sample approach and it may not cover all possible cases.

I hope this information helps. If you have any additional questions, please let me know. 

Regards,
Dess
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Ras Ran
Top achievements
Rank 2
Iron
Veteran
Iron
answered on 21 Feb 2020, 01:00 PM
how to change the given Pinned Row Back Color ?

 

dgvReturn.Rows[0].IsPinned = true;
dgvReturn.Rows[0].PinPosition = PinnedRowPosition.Bottom;

 

 

0
Nadya | Tech Support Engineer
Telerik team
answered on 25 Feb 2020, 06:21 AM

Hello,

You can change the BackColor of the pinned rows by handling the CellFormatting event:

this.radGridView1.Rows[3].IsPinned = true;

private void RadGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
{
    if (e.RowIndex == 3)
    {
        e.CellElement.BackColor = Color.Red;
        e.CellElement.GradientStyle = GradientStyles.Solid;
    }
    else
    {
        e.CellElement.ResetValue(LightVisualElement.BackColorProperty);
        e.CellElement.ResetValue(LightVisualElement.GradientStyleProperty);
    }
}

I hope this helps. Do not hesitate to contact us if you have other questions.

Regards,
Nadya
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Ras Ran
Top achievements
Rank 2
Iron
Veteran
Iron
answered on 25 Feb 2020, 01:04 PM
 
thank you so much Nadya...its worked perfectly
Tags
GridView
Asked by
Cernat
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Cernat
Top achievements
Rank 1
Ras Ran
Top achievements
Rank 2
Iron
Veteran
Iron
Nadya | Tech Support Engineer
Telerik team
Share this question
or