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

[Solved] Checkbox in a column

4 Answers 214 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.
Archer Admin
Top achievements
Rank 1
Archer Admin asked on 23 Dec 2008, 09:20 PM
Is possible to have a checkbox in a column? If so, how do you do that?

4 Answers, 1 is accepted

Sort by
0
Hristo Deshev
Telerik team
answered on 30 Dec 2008, 10:52 AM
Hello Archer,

RadGridView will auto-detect the type of a column and enable the corresponding editor when a cell enters in edit mode. For now, if you want the editor, in your case a checkbox, to be displayed all the time a simple custom style should be applied to your boolean column.

I have prepared a sample application that demonstrates how you can create a checkbox column.
Feel free to check it out.

All the best,
Hristo Deshev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
phlogiston
Top achievements
Rank 1
answered on 02 Mar 2010, 01:44 PM
Hello Hristo,

Thank you for this example, it works very well for me. My GridView is bound to a collection of a class with a string and a boolean property, both are displayed properly with a text and a checkbox column.
My problem is, that when editing the text property in the grid, the changes commit fine, whereas (un)checking the boxes in the other column does never change the boolean property of the class. What would be your recommendation here?

XAML:
        <Grid.Resources> 
            <!--Create custom style for our bool column--> 
            <Style x:Key="BooleanColumnStyle" TargetType="gridView:GridViewCell"
                <Setter Property="Template"
                    <Setter.Value> 
                        <ControlTemplate TargetType="gridView:GridViewCell"
                            <Border HorizontalAlignment="Stretch"
                                <CheckBox HorizontalAlignment="Center" IsChecked="{Binding Path=Mandatory}"/> 
                            </Border> 
                        </ControlTemplate> 
                    </Setter.Value> 
                </Setter> 
            </Style> 
        </Grid.Resources> 
 
        <telerikGridView:RadGridView x:Name="grid" AutoGenerateColumns="False" ColumnsWidthMode="Fill" ValidationMode="Row" AddingNewDataItem="grid_AddingNewDataItem" CanUserDeleteRows="False" CanUserInsertRows="True" > 
            <telerikGridView:RadGridView.Columns> 
                <telerikGridView:GridViewDataColumn Width="230" DataMemberBinding="{Binding Name}"/> 
                <telerikGridView:GridViewDataColumn Width="100"  CellStyle="{StaticResource BooleanColumnStyle}" /> 
            </telerikGridView:RadGridView.Columns> 
        </telerikGridView:RadGridView> 

I have tried setting the second column's DataMemberBinding to the boolean property with no effect.

Many thanks in advance!

  
0
Rossen Hristov
Telerik team
answered on 03 Mar 2010, 01:11 PM
Hello phlogiston,

If you just leave the column without touching it it will display check-boxes when it sees that the property is boolean. You do not have to do all these things. Take a look at this online example.

If for some reason you really need to do this with the CellStyle then your Binding has to be TwoWay.

By the way, the proper way to do this would be with a normally bound column and CellEditTemplate. Take a look at this example and this blog post for more information.

I hope this helps.

Best wishes,
Ross
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
phlogiston
Top achievements
Rank 1
answered on 04 Mar 2010, 09:18 AM
Hi Ross,

Thank you for the response, i understand now that i have indeed thought of things way too complicated. I have used the example Hristo provided and it seemed well-fitting to me, when it could have been much simpler than this.
Well, sometimes one just can't help. ;)

Best wishes!
Tags
GridView
Asked by
Archer Admin
Top achievements
Rank 1
Answers by
Hristo Deshev
Telerik team
phlogiston
Top achievements
Rank 1
Rossen Hristov
Telerik team
Share this question
or