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

9 posts, 0 answers
  1. Eric
    Eric avatar
    4 posts
    Member since:
    Jul 2010

    Posted 16 Aug 2010 Link to this post

    The title of the thread says it all:

    Me.RadGridView1.Rows(0).Cells(0).Style.BackColor = Color.Yellow

    Me.RadGridView1.Rows(0).Cells(0).Style.BackColor2 = Color.Yellow

    Me.RadGridView1.Rows(0).Cells(0).Style.BackColor3 = Color.Yellow

    Me.RadGridView1.Rows(0).Cells(0).Style.BackColor4 = Color.Yellow

    Me.RadGridView1.Rows(0).Cells(0).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.RadGridView1.Rows(0).Cells(0).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



     

     

     

     

  2. Bernd Mueller
    Bernd Mueller avatar
    38 posts
    Member since:
    May 2010

    Posted 17 Aug 2010 Link to this post

    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
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Eric
    Eric avatar
    4 posts
    Member since:
    Jul 2010

    Posted 17 Aug 2010 Link to this post


    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
  5. Eric
    Eric avatar
    4 posts
    Member since:
    Jul 2010

    Posted 17 Aug 2010 Link to this post

    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

     

  6. erwin
    erwin avatar
    358 posts
    Member since:
    Dec 2006

    Posted 18 Aug 2010 Link to this post

    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
  7. Martin Vasilev
    Admin
    Martin Vasilev avatar
    1061 posts

    Posted 19 Aug 2010 Link to this post

    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
  8. Eric
    Eric avatar
    4 posts
    Member since:
    Jul 2010

    Posted 19 Aug 2010 Link to this post

    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

  9. Jesús
    Jesús avatar
    3 posts
    Member since:
    Sep 2010

    Posted 17 Sep 2010 Link to this post

    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)

  10. Martin Vasilev
    Admin
    Martin Vasilev avatar
    1061 posts

    Posted 23 Sep 2010 Link to this post

    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
Back to Top
UI for WinForms is Visual Studio 2017 Ready