GridViewCheckBoxColumn Hides Row Selection Color

4 posts, 1 answers
  1. Simon
    Simon avatar
    4 posts
    Member since:
    Oct 2013

    Posted 14 Jul Link to this post

    When one or more rows are selected in a RadGridView, their cell backgrounds change to (by default) a pale orange color, with gradation I think.  But, when this happens, the backgrounds of those cells of the selected rows that are in GridViewCheckBoxColumns remain white.  I want to show the row selection color in the GridViewCheckBoxColumn cells, to make them consistent with the other cells in the selected rows.

    I think the problem is that the embedded CheckBox completely fills the cell, obscuring the cell background proper.  If that is the case, then perhaps a solution would be to set the CheckBox's own background to transparent, so that the underlying cell color changes (when the row is selected and deselected) would be visible. 

    If all that is true, then what I specifically want to know is how to set the background color of the embedded CheckBox in every cell of every GridViewCheckBoxColumn in the grid to transparent when the grid is shown.

  2. Answer
    Stefan Nenchev
    Admin
    Stefan Nenchev avatar
    281 posts

    Posted 19 Jul Link to this post

    Hello Simon,

    Please have in mind that the GridViewCheckBoxColumn does not use a CheckBox but a GridViewCheckBox element as a default editor. With this in mind, in order to achieve the desired behavior, you need to edit the ControlTemplate of the GridViewCheckBox, inspect the whole structure and set some of the elements` backgrounds to transparent. I have created a sample project that implements the desired behavior. 

    You can also use a GridViewDataColumn and explicitly set its CellTemplate to contain a standard CheckBox. Eventually, you can change its control template(as in the GridViewCheckBoxColumn) or directly set the background color:

    <telerik:GridViewDataColumn DataMemberBinding="{Binding IsChampion}">
                       <telerik:GridViewDataColumn.CellTemplate>
                           <DataTemplate>
                               <CheckBox IsChecked="{Binding IsChampion}" Background="Transparent"></CheckBox>
                           </DataTemplate>
                       </telerik:GridViewDataColumn.CellTemplate>
    </telerik:GridViewDataColumn>

    However, this will not change all components(within the CheckBox template) backgrounds so modifying the whole template is the best approach. I have created a sample project for your reference with these two approaches. Please review it and consider which one suits your scenario the best.

    Please update me whether the information was useful. Of course, if you have any further questions or concerns, do not hesitate to contact us.

    Regards,
    Stefan Nenchev
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Simon
    Simon avatar
    4 posts
    Member since:
    Oct 2013

    Posted 18 Sep in reply to Stefan Nenchev Link to this post

    Thanks, Stefan. Sorry to be so late replying.  Forum thread tracking is not working for me, so I did not see your post at the time.  And, for reasons unrelated to this thread but to do with specific application requirements, we have decided not to implement the check boxes in the grids with GridViewCheckBoxColumn.  Instead, we have developed our own unsophisticated alternative that will meet our needs.

    So we have not implemented your solution in our application.  However, I have looked at and ran your sample application.  It does exactly what I was asking for.

    Your sample provides solutions for both GridViewCheckBoxColumn and Checkbox.  They both work.  Our application's grids have many check boxes.  We did try implementing them with Checkbox but encountered slow grid building and scrolling performance.  There were no such performance problems with either GridViewCheckBoxColumn or our light-weight custom solution.  I mention this not at all as a criticism of the solution sample, but just as something anyone implementing a RadGridView with many check boxes should consider.

    Cheers, Simon

  5. Stefan Nenchev
    Admin
    Stefan Nenchev avatar
    281 posts

    Posted 20 Sep Link to this post

    Hi Simon,

    Thanks for the update and sharing the additional information. I am glad to hear that you have found a solution to your requirement as well. I just wanted to correct a statement from my previous reply - actually, the GridViewCheckBoxColumn uses a GridViewCheckBox in view mode and a standard CheckBox when in edit mode.

    Regards,
    Stefan Nenchev
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Back to Top