Bypass the cell selection behavior or make the rows non selectable

2 posts, 1 answers
  1. Claude
    Claude avatar
    9 posts
    Member since:
    Dec 2014

    Posted 02 Jun 2015 Link to this post

    I have a grid (Q2 2014 SP1) with several columns and one checkbox column.  The checkbox is the only information that can be modified by the users.  Now, depending on the checkbox state, I paint the row using this code (where "IsConcilie" is the checkbox's column name):

    if (row.Cells["IsConcilie"].Value.Equals(true))
    rowElement.DrawFill = true;
    rowElement.GradientStyle = GradientStyles.Solid;
    rowElement.BackColor = Color.Gray;
    rowElement.ForeColor = Color.White;
    rowElement.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local);
    rowElement.ResetValue(LightVisualElement.GradientStyleProperty, ValueResetFlags.Local);
    rowElement.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local);
    rowElement.ResetValue(LightVisualElement.ForeColorProperty, ValueResetFlags.Local);

    The problem I have is when one of the cell is clicked, the cell is selected and painted using the default colors which makes the cell hard to read because it keeps my foreground color setting.

    Since only the checkbox can be modified, is here a way we can prevent the selected cell to paint using the default painting behavior?  Or how can I handle the painting of the cell myself and bypass the default settings?  Or even, can we make the rows non-selectable?


  2. Answer
    Hristo avatar
    1061 posts

    Posted 03 Jun 2015 Link to this post

    Hello Claude,

    Thank you for writing.

    You could reach the desired behavior in couple ways:
    1. Make use of the formatting events, in the CellFormatting event you would also need to perform a check if the passed cell is current and then apply the color styling. I am sending you an example project in which I used your code regarding the coloring of the rows. For the current cell I am just taking the back color of the row so that it will not get highlighted. Detailed information you can also find in the following topics of our documentation: Formatting Rows, Formatting Cells.
    2. As an alternative approach you could directly modify the theme you are using and assign for the proper states of the required cells a repository item. This task can be accomplished with the help of our Visual Style Builder tool. For instructions how to use the newly created theme please check this article: Using Custom Themes. I am also sending you short video demonstrating how an existing repository can be removed and a newly created one added.

    In addition I am also sending you a gif file showing how the grid looked on my end after I handled the CellFormatting event.

    I hope this information was useful. Should you have further questions please do not hesitate to write back.

    Hristo Merdjanov
    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