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

Checkbox problem

2 Answers 50 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Nelson
Top achievements
Rank 1
Nelson asked on 20 Sep 2011, 07:29 PM
Hi there,

In our application we use in a GridView one checkBox column. We've tried to do that in two ways.
The first way, we used GridViewCheckBoxColumn, like this:

<telerik:RadGridView
Name="GrdParticipantesReuniao"
Background="Transparent"
ItemsSource="{Binding Path=DataContext.OCParticipantesReuniao,ElementName=LayoutRoot}"
BorderThickness="0"
Width="340" MaxHeight="300" Margin="0 10 0 0"
RowHeight="20"
AutoGenerateColumns="False"
SelectionMode="Single"
Cursor="Hand"
RowIndicatorVisibility="Collapsed"
IsFilteringAllowed="True"
ShowGroupPanel="False"
CanUserReorderColumns="False"
CanUserResizeColumns="False"
ShowColumnFooters="False" ShowInsertRow="False"
telerik:RadDragAndDropManager.AllowDrop="True">
<swi:Interaction.Triggers>
<swi:EventTrigger EventName="SelectionChanged">
<esi:CallDataMethod Method="GrdParticipantesReuniaos_SelectionChanged"/>
</swi:EventTrigger>
</swi:Interaction.Triggers>
<telerik:RadGridView.Columns>
<telerik:GridViewDataColumn DataMemberBinding="{Binding FuncoesreuniaoProp.DesignacaoProp}" Header="Função" Width="0.25*" IsReadOnly="True"/>
<telerik:GridViewDataColumn DataMemberBinding="{Binding EntidadesProp,Converter={StaticResource ConcatenaTitulo}}" Header="Nome" Width="0.6*" IsReadOnly="True"/>
<telerik:GridViewCheckBoxColumn DataMemberBinding="{Binding Seleccionado,Mode=TwoWay}" Header="Inc." Width="0.15*" IsReadOnly="false"/>
 </telerik:RadGridView.Columns>
                        </telerik:RadGridView>

However, with this code we had two problems: first, the comboBox seems like disabled and, in the second approach we had problems to select the option (we must click three times to make a positive check).

So, we've tried yet another approach.
We've searched inn telerik´s forum and found this solution, using GridViewColumn.CellStyle.

<telerik:RadGridView
Name="GrdParticipantesReuniao"
Background="Transparent"
ItemsSource="{Binding Path=DataContext.OCParticipantesReuniao,ElementName=LayoutRoot}"
BorderThickness="0"
Width="340" MaxHeight="300" Margin="0 10 0 0"
RowHeight="20"
AutoGenerateColumns="False"
SelectionMode="Single"
Cursor="Hand"
RowIndicatorVisibility="Collapsed"
IsFilteringAllowed="True"
ShowGroupPanel="False"
CanUserReorderColumns="False"
CanUserResizeColumns="False"
ShowColumnFooters="False" ShowInsertRow="False"
telerik:RadDragAndDropManager.AllowDrop="True">
<swi:Interaction.Triggers>
<swi:EventTrigger EventName="SelectionChanged">
<esi:CallDataMethod Method="GrdParticipantesReuniaos_SelectionChanged"/>
</swi:EventTrigger>
</swi:Interaction.Triggers>
<telerik:RadGridView.Columns>
<telerik:GridViewDataColumn DataMemberBinding="{Binding FuncoesreuniaoProp.DesignacaoProp}" Header="Função" Width="0.25*" IsReadOnly="True"/>
<telerik:GridViewDataColumn DataMemberBinding="{Binding EntidadesProp,Converter={StaticResource ConcatenaTitulo}}" Header="Nome" Width="0.6*" IsReadOnly="True"/>
<telerik:GridViewColumn Header="Check">
<telerik:GridViewColumn.CellStyle>
<Style TargetType="telerik:GridViewCell">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="telerik:GridViewCell">
<Border Padding="5,0,5,0" BorderThickness="0,0,1,1" BorderBrush="#FFB3B3B3">
<CheckBox HorizontalAlignment="Center" VerticalAlignment="Center" IsChecked="{Binding Path=DataContext.OCParticipantesReuniao.Seleccionado,Mode=TwoWay,ElementName=GrdParticipantesReuniao}"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</telerik:GridViewColumn.CellStyle>
</telerik:GridViewColumn>


The problem is that we use MVVM and we can´t bind Seleccionado Property, because this property is inside of control template.Can you please give us an idea of how to do it?


Thanks in advance,
Nelson

2 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 21 Sep 2011, 09:02 AM
Hello Nelson,

You may define CellTemplate for a GridViewDataColumn and to place a CheckBox inside. For example:

<telerik:GridViewDataColumn DataMemberBinding="{Binding IsChampion}">
                    <telerik:GridViewDataColumn.CellTemplate>
                        <DataTemplate>
                            <CheckBox IsChecked="{Binding IsChampion, Mode=TwoWay}" />
                        </DataTemplate>
                    </telerik:GridViewDataColumn.CellTemplate>
                </telerik:GridViewDataColumn>
 

Kind regards,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Nelson
Top achievements
Rank 1
answered on 21 Sep 2011, 09:09 AM
Hi Maya,

Thanks for the quick reply. Your suggestion solve the problem.

Thanks, now works good.

Nelson
Tags
GridView
Asked by
Nelson
Top achievements
Rank 1
Answers by
Maya
Telerik team
Nelson
Top achievements
Rank 1
Share this question
or