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

[Solved] GridViewSelectColumn checkbox alignment

1 Answer 262 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.
devster
Top achievements
Rank 1
devster asked on 06 Nov 2009, 03:01 PM
Using version Q2.

Hello,

What's the easiest way to change the alignment of the checkbox in a GridViewSelectColumn (eg Center)

The TextAlignment has no influence.

Thanks.

1 Answer, 1 is accepted

Sort by
0
Accepted
Milan
Telerik team
answered on 09 Nov 2009, 01:57 PM
Hello dev,

Currently there is not automatic way to do that but you can easily do something like that:

<telerikGrid:RadGridView Name="playersGrid" SelectionMode="Extended" 
                         AutoGenerateColumns="True">
    <telerikGrid:RadGridView.Columns>
        <telerikGrid:GridViewSelectColumn Width="200">
            <telerikGrid:GridViewSelectColumn.Header>
                    <CheckBox HorizontalAlignment="Center" Click="CheckBox_Click" />
            </telerikGrid:GridViewSelectColumn.Header>
        </telerikGrid:GridViewSelectColumn>
    </telerikGrid:RadGridView.Columns>
</telerikGrid:RadGridView>

private void CheckBox_Click(object sender, RoutedEventArgs e)
{
    var checkBox = (CheckBox)sender;
    var parentGrid = checkBox.ParentOfType<GridViewDataControl>();
  
    if (checkBox.IsChecked.Value)
        parentGrid.SelectAll();
    else
        parentGrid.UnselectAll();
}

If you would like the checkboxes of all cells to have the same alignment you can create a simple cell style and use the CellStyle property of the GridViewSelectColumn:

<Style x:Key="CenteredContentCellStyle" TargetType="gridView:GridViewCell">
    <Setter Property="HorizontalContentAlignment" Value="Center"/>
</Style>

Hope this helps.

All the best,
Milan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
GridView
Asked by
devster
Top achievements
Rank 1
Answers by
Milan
Telerik team
Share this question
or