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

Checkboxcolumn checked conditional formatting at runtime

4 Answers 155 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Felice
Top achievements
Rank 1
Felice asked on 04 Jan 2014, 06:55 AM
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?

4 Answers, 1 is accepted

Sort by
0
Accepted
George
Telerik team
answered on 08 Jan 2014, 02:14 PM
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 >>
0
Felice
Top achievements
Rank 1
answered on 08 Jan 2014, 02:41 PM
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
0
Felice
Top achievements
Rank 1
answered on 08 Jan 2014, 02:44 PM
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
0
George
Telerik team
answered on 09 Jan 2014, 03:56 PM
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 >>
Tags
GridView
Asked by
Felice
Top achievements
Rank 1
Answers by
George
Telerik team
Felice
Top achievements
Rank 1
Share this question
or