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

CellFormatting doesn't allow BackColor to be set?

5 Answers 199 Views
GridView
This is a migrated thread and some comments may be shown as answers.
rich c
Top achievements
Rank 1
rich c asked on 03 Aug 2009, 02:55 PM
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

5 Answers, 1 is accepted

Sort by
0
Boryana
Telerik team
answered on 03 Aug 2009, 03:02 PM
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.
0
Subh
Top achievements
Rank 1
answered on 24 Sep 2009, 01:27 PM
Hi,
     Kindly, please share the solution. It would be really helpful.

Thanks in advance
Subh
0
Jack
Telerik team
answered on 26 Sep 2009, 06:11 AM
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.
0
Coby
Top achievements
Rank 1
answered on 29 May 2012, 05:29 AM
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
0
Jack
Telerik team
answered on 01 Jun 2012, 07:43 AM
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 >>
Tags
GridView
Asked by
rich c
Top achievements
Rank 1
Answers by
Boryana
Telerik team
Subh
Top achievements
Rank 1
Jack
Telerik team
Coby
Top achievements
Rank 1
Share this question
or