Center Checkbox in GridViewCheckBoxColumn

11 posts, 1 answers
  1. Ristogod
    Ristogod avatar
    63 posts
    Member since:
    Aug 2008

    Posted 27 Oct 2010 Link to this post

    How do you center the checkbox in the GridViewCheckBoxColumn? My stays Left aligned. I tried setting the TextAlignment to center, but it does nothing.
  2. Answer
    Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 27 Oct 2010 Link to this post

    Hello Ristogod,

    You can use a Style to achieve that:

    <telerik:GridViewCheckBoxColumn DataMemberBinding="{Binding IsActive}" >
        <telerik:GridViewCheckBoxColumn.CellStyle>
            <Style TargetType="telerik:GridViewCell">
                <Setter Property="HorizontalContentAlignment" Value="Center" />
            </Style>
        </telerik:GridViewCheckBoxColumn.CellStyle>
    </telerik:GridViewCheckBoxColumn>

    Hope this helps.

    Sincerely yours,
    Veselin Vasilev
    the Telerik team
    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 Public Issue Tracking system and vote to affect the priority of the items
  3. UI for WPF is Visual Studio 2017 Ready
  4. LM IT
    LM IT avatar
    9 posts
    Member since:
    Feb 2014

    Posted 03 Oct 2014 Link to this post

    After setting the CellStyle in the latest UI for WPF version using the Office 2013 Theme my checkbox disappears. Any ideas on how to get this working?
  5. Vanya Pavlova
    Admin
    Vanya Pavlova avatar
    2019 posts

    Posted 03 Oct 2014 Link to this post

    Hello LM IT,


    You should inherit the base style and override only HorizontalContentAlignment property of the cell, as proposed below: 

    <telerik:RadGridView ItemsSource="{Binding Collection}">
                <telerik:RadGridView.Columns>
                    <telerik:GridViewCheckBoxColumn>
                        <telerik:GridViewCheckBoxColumn.CellStyle>
            <Style TargetType="telerik:GridViewCell" BasedOn="{StaticResource GridViewCellStyle}">
                <Setter Property="HorizontalContentAlignment" Value="Center" />
            </Style>
        </telerik:GridViewCheckBoxColumn.CellStyle>
                        </telerik:GridViewCheckBoxColumn>
                    </telerik:RadGridView.Columns>
            </telerik:RadGridView>



    Regards,
    Vanya Pavlova
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  6. Warren
    Warren avatar
    3 posts
    Member since:
    Aug 2012

    Posted 11 Nov 2014 Link to this post

    I experienced this same behavior when switching to Implicit Themes. It appears that the advice provided on this page doesn't apply to implicit theming. Even the offset is now broken and I had to switch the -3 to -10 without filtering enabled, and -11 with filtering enabled. This seems like a bad solution. So you have any additional insight?
  7. Vanya Pavlova
    Admin
    Vanya Pavlova avatar
    2019 posts

    Posted 14 Nov 2014 Link to this post

    Hi Warren,


    Thank you for contacting us.

    I'm not quite sure, that I understand your points correctly.

    Can you please elaborate a bit more?
     

    Regards,
    Vanya Pavlova
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  8. Warren
    Warren avatar
    3 posts
    Member since:
    Aug 2012

    Posted 08 Dec 2014 in reply to Vanya Pavlova Link to this post

    Hi Vanya,

    The linked article from my post describes how to keep a checkbox centered in a column when you enter "edit" mode. The relevant code is this:

    checkBox.Margin = new Thickness(4, 0, -3, 0);

    However, once I moved to implicit styles, entering edit mode the checkbox began to shift again with that margin applied. I had to modify the amount of margin, and even had to modify it depending on what controls are showing in the header (like the filter when filtering is turned on). This seems fragile to me. I'm wondering if there is a better way. Depending on the situation I am using a -10 or -11 instead of a -3.
  9. Vanya Pavlova
    Admin
    Vanya Pavlova avatar
    2019 posts

    Posted 11 Dec 2014 Link to this post

    Hi Warren,


    I would like to ask you which Telerik theme you are currently using?


    Regards,
    Vanya Pavlova
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  10. Warren
    Warren avatar
    3 posts
    Member since:
    Aug 2012

    Posted 11 Dec 2014 in reply to Vanya Pavlova Link to this post

    I am using the Office2013 theme.
  11. Vanya Pavlova
    Admin
    Vanya Pavlova avatar
    2019 posts

    Posted 12 Dec 2014 Link to this post

    Hello Warren,


    Thank you for getting back to us.

    GridViewCheckBoxColumn internally applies some Margin to the CheckBox based on particular theme. 
    Since you are trying to center the cell content, when you enter edit mode the CheckBox element jumps to the left. For the time being I suggest you to apply the Margin of the CheckBox in the way you proposed. 


    Regards,
    Vanya Pavlova
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  12. Toffer
    Toffer avatar
    34 posts
    Member since:
    Sep 2015

    Posted 19 Feb in reply to Vanya Pavlova Link to this post

    Thx Vanya.  The "BasedOn" part fixed me right up.  :)
Back to Top
UI for WPF is Visual Studio 2017 Ready