CellFormatting doesn't allow BackColor to be set?

6 posts, 0 answers
  1. rich c
    rich c avatar
    1 posts
    Member since:
    Aug 2009

    Posted 03 Aug 2009 Link to this post

    I posted this before but the post seems to have vanished

    void TelerikRadGridViewEnhanced_CellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)  
            {            
                if(!(e.CellElement.RowElement is Telerik.WinControls.UI.GridTableHeaderRowElement) && TextColorOverrideFunction != null)  
                {  
                    e.CellElement.ForeColor  = TextColorOverrideFunction((e.CellElement.RowInfo.DataBoundItem as DataRowView).Row);  
                  
                }  
          } 

    This works fine and sets the foreground (text) color. However despite there being 4 BackColor properties, I can't change the back color, it is overridden by the theme. Is there a way to set the BackColor? Thanks
  2. Boryana
    Admin
    Boryana avatar
    330 posts

    Posted 03 Aug 2009 Link to this post

    Hi Rich,

    Your previous post has been changed to a Support Ticket in order to guarantee your privacy. You will be able to find it at Your Account >> Your Support >> Support Tickets.

    Kind regards,
    Boryana
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Subh
    Subh avatar
    8 posts
    Member since:
    Sep 2009

    Posted 24 Sep 2009 Link to this post

    Hi,
         Kindly, please share the solution. It would be really helpful.

    Thanks in advance
    Subh
  4. Jack
    Admin
    Jack avatar
    2333 posts

    Posted 26 Sep 2009 Link to this post

    Hi Subh,

    By default the painting of cell background is disabled. You should enable it by setting DrawFill property to true. In addition, you can select different background style by setting GradientStyle property. Here is a sample:

    void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e) 
        GridViewDataColumn column = e.CellElement.ColumnInfo as GridViewDataColumn; 
        if (column != null && column.UniqueName == "Column1"
        { 
            e.CellElement.DrawFill = true
            e.CellElement.BackColor = Color.Red; 
            e.CellElement.GradientStyle = GradientStyles.Solid; 
        } 

    I hope this helps. Should you have other questions, I will be glad to help.

    Regards,
    Jack
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  5. Coby
    Coby avatar
    1 posts
    Member since:
    Dec 2010

    Posted 29 May 2012 Link to this post

    I populate the grid with data from an xml node list, I use a for loop to search for rows that need update.  I also want to change the backcolor of some cells in the same operation.  I can not get the backcolor to change, I have tried dozens of ways, unable to figure it out.  Any help is appreciated.

    Here is the code:


    For Each row As XmlNode In xnl_02
     
        For Each gvdri As GridViewDataRowInfo In Me.rgv.Rows
     
            If gvdri.Tag = row(0).InnerText Then
                gvdri.Cells("02_").Value = FormatSystemName(row("device_id").InnerText)
                gvdri.Cells("02_").Value = row("p_id").InnerText
     
                With (gvdri.Cells("01_").Style)
                    .ForeColor = Color.Red
                    .Font = New Font("Segoe UI", 8.25, FontStyle.Bold)
                    .DrawFill = True
                    .GradientStyle = GradientStyles.Solid
                    .BackColor = Color.Red
                End With
     
            End If
        Next
     
    Next
  6. Jack
    Admin
    Jack avatar
    2333 posts

    Posted 01 Jun 2012 Link to this post

    Hello Coby,

    When customizing a large number of cells, the best option is to handle the CellFormatting event like demonstrated in this thread. However, if you prefer to use the Style property, you should set also the CustomizeFill property. Consider the sample below:

    For Each row As XmlNode In xnl_02
      
        For Each gvdri As GridViewDataRowInfo In Me.rgv.Rows
      
            If gvdri.Tag = row(0).InnerText Then
                gvdri.Cells("02_").Value = FormatSystemName(row("device_id").InnerText)
                gvdri.Cells("02_").Value = row("p_id").InnerText
      
                With (gvdri.Cells("01_").Style)
                    .ForeColor = Color.Red
                    .Font = New Font("Segoe UI", 8.25, FontStyle.Bold)
                    .DrawFill = True
                    .GradientStyle = GradientStyles.Solid
                    .BackColor = Color.Red
                    .CustomizeFill = True
                End With
      
            End If
        Next
      
    Next

    If you need further assistance, I will be glad to help.
     
    All the best,
    Jack
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
Back to Top