This is a migrated thread and some comments may be shown as answers.
Center Checkbox in GridViewCheckBoxColumn
10 Answers 516 Views
This is a migrated thread and some comments may be shown as answers.
Ristogod
Top achievements
Rank 2
Ristogod asked on 27 Oct 2010, 04:16 PM
How do you center the checkbox in the GridViewCheckBoxColumn? My stays Left aligned. I tried setting the TextAlignment to center, but it does nothing.

10 Answers, 1 is accepted

Sort by
0
Accepted
Veselin Vasilev
Telerik team
answered on 27 Oct 2010, 04:26 PM
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
0
LM IT
Top achievements
Rank 2
answered on 03 Oct 2014, 10:57 AM
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?
0
Vanya Pavlova
Telerik team
answered on 03 Oct 2014, 11:09 AM
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.
 
0
Warren
Top achievements
Rank 1
answered on 11 Nov 2014, 04:25 PM
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?
0
Vanya Pavlova
Telerik team
answered on 14 Nov 2014, 01:22 PM
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.

 
0
Warren
Top achievements
Rank 1
answered on 08 Dec 2014, 06:47 PM
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.
0
Vanya Pavlova
Telerik team
answered on 11 Dec 2014, 11:40 AM
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.

 
0
Warren
Top achievements
Rank 1
answered on 11 Dec 2014, 03:44 PM
I am using the Office2013 theme.
0
Vanya Pavlova
Telerik team
answered on 12 Dec 2014, 04:32 PM
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.

 
0
Toffer
Top achievements
Rank 2
answered on 19 Feb 2016, 10:19 PM
Thx Vanya.  The "BasedOn" part fixed me right up.  :)
Asked by
Ristogod
Top achievements
Rank 2
Answers by
Veselin Vasilev
Telerik team
LM IT
Top achievements
Rank 2
Vanya Pavlova
Telerik team
Warren
Top achievements
Rank 1
Toffer
Top achievements
Rank 2
Share this question
or