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

checkbox cell not in specific row

5 Answers 51 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Orit
Top achievements
Rank 1
Orit asked on 16 Aug 2009, 10:22 AM
Hello
I want to add a check box column
but in a specific row (Value="{x:Null}")
I dont want to see the checkbox
just to have an empty cell
one more thing-
in that specific row I want to have a specific style to the all row
this is my code

the style to the all row
<Style TargetType="{x:Type telerik:GridViewRow}">  
                                <Style.Triggers> 
                                    <DataTrigger Binding="{Binding Path=ParentID}" Value="{x:Null}">  
                                       <DataTrigger.Setters> 
                                            <Setter Property="FontSize" Value="12" /> 
                                            <Setter Property="FontWeight" Value="Bold" /> 
                                        </DataTrigger.Setters> 
                                    </DataTrigger> 
                                </Style.Triggers> 
                            </Style> 
in this row I dont want to see the check box.

the checkbox column
<ControlTemplate x:Key="cellTemplate" TargetType="{x:Type telerik:GridViewCell}">  
                                    <Border BorderBrush="DarkGray" BorderThickness="0,0,1,1">  
                                        <CheckBox IsChecked="{Binding Field.Record.Data.General, RelativeSource={RelativeSource TemplatedParent}}"   
                                                    HorizontalAlignment="Center" VerticalAlignment="Center" /> 
</Border> 
</ControlTemplate> 


Thanks!

5 Answers, 1 is accepted

Sort by
0
Milan
Telerik team
answered on 19 Aug 2009, 01:54 PM

Hello Orit,

Could you provide some clarification for your scenario so that we can send you the correct solution.

I couldn't understand if you would like to have just a single column or several columns? Would you like to show another column besides the CheckBox one? 

I understand that you do not want to see CheckBox column when "Value=Null" but I am not sure which Value are you refering to? Is that the value of the ParentID property or another property?

If the visibility of the CheckBox column is determined by a property like ParentID should that property (for example ParentID) be displayed in the grid in another column? Or it is just used to determine the visibility?

Sincerely yours,

Milan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Orit
Top achievements
Rank 1
answered on 20 Aug 2009, 05:52 AM
Hello
One of the columns in my DataTable is "ParentID"
I dont show its value in the grid.
One of the columns is a checkbox column
in a row that ParentID=Null I dont want to see the checkbox
(by the way, in a row that ParentID=Null I want to have FontWeight etc)
Is it possible?
Thanks
0
Milan
Telerik team
answered on 20 Aug 2009, 05:30 PM
Hello Orit,

I am sending you a project that demonstrates how this could be done. The XAML is quite simple:

<Grid> 
    <Grid.Resources> 
        <DataTemplate x:Key="EmptyCellTemplate">  
            <Border/> 
        </DataTemplate> 
        <Style x:Key="CustomCellStyle" TargetType="{x:Type telerik:GridViewCell}">  
            <Style.Triggers> 
                <DataTrigger Binding="{Binding Path=Subject}" Value="{x:Null}">  
                    <Setter Property="ContentTemplate" Value="{StaticResource EmptyCellTemplate}"/>  
                </DataTrigger> 
            </Style.Triggers> 
        </Style> 
    </Grid.Resources> 
    <telerik:RadGridView Name="RadGridView1" AutoGenerateColumns="False" > 
        <telerik:RadGridView.Columns> 
            <telerik:GridViewDataColumn DataMemberPath="General"   
                                        HeaderText="CheckBox" CellStyle="{StaticResource CustomCellStyle}"/>  
        </telerik:RadGridView.Columns> 
    </telerik:RadGridView> 
</Grid> 

The only question that remains is: if CheckBox is show what property it is bound to? In the sample I check if the Sender property is null but for your case that should be the ParentID property and I am also binding the CheckBox to a property called General, which is probably different for your scenario.

Hope this help. 


All the best,
Milan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Erez
Top achievements
Rank 1
answered on 04 Nov 2009, 06:21 AM

Hello,

Could you please help me to understand why this works,

 

<CheckBox IsChecked="{Binding Field.Record.Data.General, RelativeSource={RelativeSource TemplatedParent}}"

 

<ControlTemplate x:Key="cellTemplate" TargetType="{x:Type telerik:GridViewCell}">

<Border BorderBrush="DarkGray" BorderThickness="0,0,1,1">

<CheckBox IsChecked="{Binding Field.Record.Data.General, RelativeSource={RelativeSource TemplatedParent}}"

HorizontalAlignment="Center" VerticalAlignment="Center" />

</Border>

</ControlTemplate>

 

in particular

"Field.Record.Data.General" ?

I tried investigating the GridViewDataColumn object using reflection, but could not come to an answer or find "Field.Record.Data".

Thanks.

 

 

 

 

0
Milan
Telerik team
answered on 05 Nov 2009, 12:38 PM

Hello Erez,

Well, the GridViewCell has property called Field which in turn has a property Record which in tern has a property Data which is actually a reference to a data item . Since your data items have a property General I could write "Field.Record.Data.General".

Basically the binding will try to resolve the specified property path and if such path does not exist (for example the data items do not have a property General) the binding will fail.

Regards,

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
Orit
Top achievements
Rank 1
Answers by
Milan
Telerik team
Orit
Top achievements
Rank 1
Erez
Top achievements
Rank 1
Share this question
or