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

Set BackColor of cells with Q2 2010 SP1??????

8 Answers 174 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Eric
Top achievements
Rank 1
Eric asked on 16 Aug 2010, 03:29 PM
The title of the thread says it all:

Me.RadGridView.Rows().Cells().Style.BackColor = Color.Yellow

Me.RadGridView.Rows().Cells().Style.BackColor = Color.Yellow

Me.RadGridView.Rows().Cells().Style.BackColor = Color.Yellow

Me.RadGridView.Rows().Cells().Style.BackColor = Color.Yellow

Me.RadGridView.Rows().Cells().Style.DrawFill = True

I understand that the cell element is gone but this code worked last build using the CellElement but not with the new Style object. I would assume there is a way to change the back color of a cell at run-time. Please give me the correct way so my code will work. Thank you.


OK More Info.....

Me.RadGridView.Rows().Cells().Style.ForeColor = Color.Yellow

this works!!! soooo....just maybe this is something you need to fix with backcolor.. :-)

I find it hard to believe there is no current way with the latest version to set the backcolor of cells at run-time, so any code that works I'll take at this point.

Eric



 

 

 

 

8 Answers, 1 is accepted

Sort by
0
Bernd Mueller
Top achievements
Rank 1
answered on 17 Aug 2010, 01:55 PM
How about using the CellFormatting Event?

Private Sub DataGridViewMain_CellFormatting(ByVal sender As System.Object, ByVal e As Telerik.WinControls.UI.CellFormattingEventArgs) Handles RadGridView1.CellFormatting
                e.CellElement.DrawFill = True
                e.CellElement.NumberOfColors = 1
        e.CellElement.BackColor = Color.Yellow
End Sub
0
Eric
Top achievements
Rank 1
answered on 17 Aug 2010, 02:54 PM

Wow, I can't believe the event args has the CellElement object in it. Is this by design Telerik?? I have no idea why you would remove CellElement from the actual Cell Object and allow you to access it through an Event Args object. Anyways....

Thanks for the help but this doesn't work for me.  Basically, I have several grids on one form and I am keeping them all in sync by coloring.
 
For example if you select a cell in one grid it will highlight every cell for that column in all grids. Using cell formatting limits me to only the Cell that is past into the event which will not be all the cells that need their backcolored changed. Thanks.

Eric
0
Eric
Top achievements
Rank 1
answered on 17 Aug 2010, 06:34 PM

Found a Workaround (Thanks to Julian's reply to my other post). I don't know about the performance compared to the old way,
I haven't changed all my grids' code to the workaround. Anyways thank you very much for the support! :-)

 

For

 

Each row As GridViewRowInfo In Me.RadGridView1.Rows

 

 

    Dim cell As GridCellElement

 

    cell =

Me.RadGridView1.TableElement.GetCellElement(row, Me.RadGridView1.Columns(0))

 

    cell.BackColor = Color.Yellow

    cell.DrawFill =

True

 

 

Next

 

0
erwin
Top achievements
Rank 1
Veteran
Iron
answered on 18 Aug 2010, 04:20 PM
Eric,

I guess this behaviour is by Design for performance reasons, since the CellElement is only available for currently visible cells.
The CellFormatting event is only fired for Cells that are currently visible, so that makes sense.

Depending on what the user did with your window, you cannot know which elements of the grid are currently visible an therefore have a valid CellElement. On large grids, creating CellElements to hold information about visual representation that is never needed (since the cell is not currently shown) leads to considerable consumption of system resources.

However, I have other problems with CellFormatting and LoadLayout() with SP1 / Internal Build 813

Regards
Erwin
0
Martin Vasilev
Telerik team
answered on 19 Aug 2010, 04:30 PM
Hello everyone,

Thanks for writing.

As I have already answered in your support ticket, you can use the CellFormatting event. It seems that you have received very similar suggestions here.

However, I have investigated this further and can confirm that the Style property is designed to do exactly 
what you require. More information on this topic could be found in following blog post. Unfortunately, we have some issues with this particular property and we will do our best to address them in our next major release. For the time being you will have to use the CellFormatting event.

I hope this helps. Let me know if you have further questions.

Regards,
Martin Vasilev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Eric
Top achievements
Rank 1
answered on 19 Aug 2010, 07:28 PM
Sorry, I'm not trying to be a pain, but as I stated in the previous reply:

**About using CellFormatting Event**
----------------------

Thanks for the help but this doesn't work for me.  Basically, I have several grids on one form and I am keeping them all in sync by coloring.
 
For example if you select a cell in one grid it will highlight every cell for that column in all grids. Using cell formatting limits me to only the Cell that is past into the event which will not be all the cells that need their backcolored changed. Thanks.
--------------------------

So CellFormatting is not a solution for me.  However, I was able to use my workaround code and it is fast. I don't know if it is do to the fact that the backcolor property on the new Style object isn't working but looping through ALL the cells and setting this is way to slow. That is why in my other forum posts I wanted to know how to get that the "Visible" Cells. Basically if the CellElement is nothing(null) that means it is not visible. Thank you all for all the help. I have a working solution for now, so I am happy.

Eric

0
Jesús
Top achievements
Rank 1
answered on 17 Sep 2010, 11:46 PM

Thank you Eric!! You don't know how much you helped me. I had the same problem than you and now i found the solution in your post. I had been trying using the Style property of the cell but it doesn't work (im still wondering why =/ )

gridviewName.Rows[0].Cells[1].Style.BackColor = Color.White;

gridviewName.Rows[0].Cells[1].Style.DrawFill = true;

But finally i used your code and it works! I searched in many forums (including this) and the solution was always "You must use the CellFormatting event". But, like you,  i can use it because it only works with the cell which is passed into the event. I think the Telerik team should look into that problem.

Here is your same code but in C#, in case someone else need it:

GridCellElement cell;
cell = this.gridviewName.TableElement.GetCellElement(this.gridviewName.Rows[0], this.gridviewName.Columns[1]);
cell.BackColor = Color.Violet;
cell.DrawFill = true;

(note: sorry for my english)

0
Martin Vasilev
Telerik team
answered on 23 Sep 2010, 07:07 AM
Hello guys,

In Q2 2010 SP2 release we have improved GridViewCellInfo.Style property's functionality and now it should be used for the described scenarios. Please consider the following code as an example:
bool setBackColor = true;
private void radButton2_Click(object sender, EventArgs e)
{
    GridViewCellInfo cell = this.radGridView1.Rows[1].Cells[2];
    if (this.setBackColor)
    {
        cell.Style.CustomizeFill = true;
        cell.Style.NumberOfColors = 1;
        cell.Style.BackColor = Color.Red;
        cell.Style.ForeColor = Color.White;
    }
    else
    {
        cell.Style.ResetCell();
    }
    this.setBackColor = !this.setBackColor;
}


Sincerely yours,
Martin Vasilev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
Eric
Top achievements
Rank 1
Answers by
Bernd Mueller
Top achievements
Rank 1
Eric
Top achievements
Rank 1
erwin
Top achievements
Rank 1
Veteran
Iron
Martin Vasilev
Telerik team
Jesús
Top achievements
Rank 1
Share this question
or