Change row color with GridViewCheckBoxColumn selected

3 posts, 0 answers
  1. Rodrigo
    Rodrigo avatar
    6 posts
    Member since:
    Oct 2015

    Posted 20 Oct 2015 Link to this post

    I have a GridView with MultiSelect enabled. The standard behavior is when the user selects a row this changes the row's color and all selected rows maintain a diferent color. I want to mimic this behavior with a GridViewCheckBoxColumn.

     My GridView has a GridViewCheckBoxColumn and when it's checked, I want to change the row color. If it's unchecked, return it back to normal. Currently I'm using the ValueChanged event to capture the event of the checking and unchecking.

    private void radGridViewProducts_ValueChanged(object sender, EventArgs e)
    {
        if (this.radGridViewProducts.ActiveEditor is RadCheckBoxEditor)
        {
            this.radGridViewProducts.Rows[this.radGridViewProducts.CurrentCell.RowIndex].IsSelected = true;
        }
    }

     The code above does not change the row color. How can I acheive this?

     

    Thank you.
  2. Andreas Haeusler
    Andreas Haeusler avatar
    25 posts
    Member since:
    Nov 2009

    Posted 20 Oct 2015 in reply to Rodrigo Link to this post

    My uneducated guess:

    ​As with most of the formatting: Use the CellFormatting event, check the e.CellElement.RowInfo for the state of your GridViewCheckBoxColumn and format accordingly.

     

    As a little kickstart check http://www.telerik.com/help/winforms/gridview-cells-formatting-cells.html

     

    One of the telerik folks will certainly provide more detailed feedback soon. 

     

  3. UI for WinForms is Visual Studio 2017 Ready
  4. Dimitar
    Admin
    Dimitar avatar
    1413 posts

    Posted 21 Oct 2015 Link to this post

    Hi Rodrigo,

    Thank you for writing.

    An example for this is available in the following article: Formatting Rows

    In addition, you should set the EditMode property of the checkbox column. This way the change will be applied immediately:
    GridViewCheckBoxColumn col = radGridView1.Columns[0] as GridViewCheckBoxColumn;
    col.EditMode = EditMode.OnValueChange;

    I hope this helps.

    Regards,
    Dimitar
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
Back to Top