Checkboxcolumn checked conditional formatting at runtime

5 posts, 1 answers
  1. Felice
    Felice avatar
    198 posts
    Member since:
    Aug 2013

    Posted 04 Jan 2014 Link to this post

    I have a grid with a role that formats the row in red if a specific decimalcolumn "Balance", calculated at grid initialization, contains a value that is less than 0. This rule is working fine.

    private void radGridView1_Initialized(object sender, EventArgs e)
           {
              radGridView1.Columns["Balance"].Expression = "Paid-Due+Expenses";
           }

    In particular situations I need to override the above rule manually and to do so I have added a checkboxcolumn bound to the db and I am trying to add a new conditional rule which make the row green if the checkbox is checked. Obviously the status change of the checkboxcolumn happens at runtime.
    I have tried in several ways but I cannot get it functional.
    How can I change the formatting of the row (to green) at runtime if the checkbox is checked?
  2. Answer
    George
    Admin
    George avatar
    500 posts

    Posted 08 Jan 2014 Link to this post

    Hi Felice,

    Thank you for contacting us.

    You will need to use the CellFormatting event of RadGridView, if your GridViewCheckBoxColumn is first, you can use the following code:
    void grid_CellFormatting(object sender, CellFormattingEventArgs e)
    {
        bool checkedRow = Convert.ToBoolean(e.Row.Cells[0].Value);
        e.CellElement.NumberOfColors = 1;
        e.CellElement.DrawFill = true;
        if (checkedRow)
        {
            e.CellElement.BackColor = Color.Green;
        }
        else
        {
            e.CellElement.BackColor = Color.Red;
        }
    }

    You can also read more about CellFormatting at: http://www.telerik.com/help/winforms/gridview-cells-formatting-cells.html.

    I hope this helps.

    Regards,
    George
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. Felice
    Felice avatar
    198 posts
    Member since:
    Aug 2013

    Posted 08 Jan 2014 Link to this post

    Hi George,
    thanks for your support.  I am working on the project right now.
    Looks like it is working but  all rows became green, checked and not checked as you can see in the attached picture.
    I have changed the "background" to "forecolor" because I need only the text to change color but this is not the problem.
    Please help.
    Thanks,
    Felice
  4. Felice
    Felice avatar
    198 posts
    Member since:
    Aug 2013

    Posted 08 Jan 2014 Link to this post

    George,
    please do not consider my last message above.
    I forgot to change the index of the cell to the checkbox column.
    Your solution is working perfectly.
    Thanks a lot for your support.
    Felice
  5. George
    Admin
    George avatar
    500 posts

    Posted 09 Jan 2014 Link to this post

    Hi Felice,

    I am glad that I was able to help. Do not hesitate to contact us, should you have further questions.

    Regards,
    George
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
Back to Top