This is a migrated thread and some comments may be shown as answers.

[Solved] What is the simplest way to center the checkboxes in a GridDataColumn?

1 Answer 153 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Geoff Hardy
Top achievements
Rank 1
Geoff Hardy asked on 25 Feb 2010, 11:12 PM

 

 

In my RadGridView, I have a column for editing a boolean property. This shows up as a checkbox which is always aligned with the left of the cell. This looks a little strange and so I would like to center the checkbox in the column. Setting the TextAlignment property does not have any effect on the checkbox. One alternative is to appear to set the CellTemplate and Edithave I can change the alignment by setting a CellTemplate and CellEditTemplate on the column as follows:

 

 

<TelerikGrid:GridViewDataColumn UniqueName="IsDeliveryComplete" Header="Complete" IsReadOnly="False" Width="70">

 

 

 

 

 

 

<TelerikGrid:GridViewDataColumn.CellTemplate>

 

 

 

 

 

 

<DataTemplate>

 

 

 

 

 

 

<CheckBox HorizontalAlignment="Center" IsChecked="{Binding IsDeliveryComplete,Mode=TwoWay}"/>

 

 

 

 

 

 

</DataTemplate>

 

 

 

 

 

 

</TelerikGrid:GridViewDataColumn.CellTemplate>

 

 

 

 

 

 

<TelerikGrid:GridViewDataColumn.CellEditTemplate>

 

 

 

 

 

 

<DataTemplate>

 

 

 

 

 

 

<CheckBox HorizontalAlignment="Center" IsChecked="{Binding IsDeliveryComplete,Mode=TwoWay}"/>

 

 

 

 

 

 

</DataTemplate>

 

 

 

 

 

 

</TelerikGrid:GridViewDataColumn.CellEditTemplate>

 

 

 

 

 

 

</TelerikGrid:GridViewDataColumn>

 

 

 

 
This seems like a lot of XAML just to center a checkbox - it there a simpler/cleaner/nicer way?

1 Answer, 1 is accepted

Sort by
0
Milan
Telerik team
answered on 26 Feb 2010, 07:30 AM
Hello Geoff Hardy,

You should add a CellStyle to your column definition to instruct the cells in this column to center their content.

<!-- xmlns:grid="clr-namespace:Telerik.Windows.Controls.GridView;assembly=Telerik.Windows.Controls.GridView" -->
<TelerikGrid:GridViewDataColumn UniqueName="IsDeliveryComplete" Header="Complete" IsReadOnly="False" Width="70">
    <TelerikGrid:GridViewDataColumn.CellStyle>
        <Style TargetType="grid:GridViewCell">
            <!-- Center the content of GridViewCell-->
            <Setter Property="HorizontalContentAlignment" Value="Center"/>
        </Style>
    </TelerikGrid:GridViewDataColumn.CellStyle>
</TelerikGrid:GridViewDataColumn>


Greetings,
Milan
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.
Tags
GridView
Asked by
Geoff Hardy
Top achievements
Rank 1
Answers by
Milan
Telerik team
Share this question
or