Override pinned columns color with the RowFormatting event

7 posts, 0 answers
  1. Cernat
    Cernat avatar
    2 posts
    Member since:
    Dec 2016

    Posted 14 Dec 2016 Link to this post

    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

     

  2. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3822 posts

    Posted 14 Dec 2016 Link to this post

    Hello Cernat,

    Thank you for writing.  

    Depending on the specific theme, RadGridView's style may be applied at 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.
  3. Cernat
    Cernat avatar
    2 posts
    Member since:
    Dec 2016

    Posted 14 Dec 2016 in reply to Dess | Tech Support Engineer, Sr. Link to this post

    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
  4. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3822 posts

    Posted 15 Dec 2016 Link to this post

    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.
  5. Ras Ran
    Ras Ran avatar
    137 posts
    Member since:
    Nov 2018

    Posted 21 Feb Link to this post

    how to change the given Pinned Row Back Color ?

     

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

     

     

  6. Nadya
    Admin
    Nadya avatar
    303 posts

    Posted 25 Feb Link to this post

    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.
  7. Ras Ran
    Ras Ran avatar
    137 posts
    Member since:
    Nov 2018

    Posted 25 Feb in reply to Nadya Link to this post

     
    thank you so much Nadya...its worked perfectly
Back to Top