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

Help with CheckBox Template

8 Answers 129 Views
GridView
This is a migrated thread and some comments may be shown as answers.
gans
Top achievements
Rank 1
gans asked on 17 May 2012, 01:50 PM
I am using the DataTemplate in the GirdViewDataColumn.CellTemplate as follows. 

<telerik:GridViewDataColumn  DataMemberBinding="{Binding Others}" ColumnGroupName="ATTRIBUTES">
                    <telerik:GridViewDataColumn.CellTemplate>
                        <DataTemplate>
                            <CheckBox Content="{Binding Path=Others}" IsChecked="{Binding Path=IsSelected,Mode=TwoWay}" Height="16" HorizontalAlignment="Left" Margin="2" VerticalAlignment="Top" />
                        </DataTemplate>
                    </telerik:GridViewDataColumn.CellTemplate>
                </telerik:GridViewDataColumn>

I want the check box to appear only when I have data in that cell. How would I achieve this? Right now, I am getting just the CheckBox in the cells where there is no data to display. 

I am attaching the screen shot of the current behavior. Any help is greatly appreciated. 

8 Answers, 1 is accepted

Sort by
0
Accepted
Dimitrina
Telerik team
answered on 17 May 2012, 02:09 PM
Hello,

You can use a CellTemplateSelector as described in this help article. When you do not have data, then you can return an empty template.

Regards,
Didie
the Telerik team

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

0
gans
Top achievements
Rank 1
answered on 17 May 2012, 03:09 PM
Thanks for the quick Response. That helps. But I have a question. Since I have Check boxes on all the Columns of my Grid, do I need Separate Template Selector for each Column of the Grid?  If I have 20 columns in the Grid, do I need 20 template selectors especially when all of them are Check box columns? 

Is there a way I can do this with one TemplateSelector in my scenario? The difference between each column would be the property I need to check for each column in the RadGrid. 

Please let me know if I am not clear. 
0
Dimitrina
Telerik team
answered on 18 May 2012, 12:01 PM
Hi,

 You can use one CellTemplateSelector, but you will have to add additional logic in order to return the most appropriate template based on the column of the templated cell. When the TemplateSelector is applied, you should check what is the column and apply the templates for that column.

Kind regards,
Didie
the Telerik team

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

0
gans
Top achievements
Rank 1
answered on 18 May 2012, 12:36 PM
Thats exactly what I thought. But was wondering how to identity which column it belongs to.  In the
SelectTemplate(object item, System.Windows.DependencyObject container)  method item is the Object and from the container, could you please let me know how to identify which column this belongs to?





0
Accepted
Dimitrina
Telerik team
answered on 18 May 2012, 02:14 PM
Hello,

 You can get the column  (that contains the current Cell) using this code:

GridViewColumn column = ((Telerik.Windows.Controls.GridView.GridViewCellBase)(container)).Column;

Based on what the column is, you should return the template.

Greetings,
Didie
the Telerik team

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

0
gans
Top achievements
Rank 1
answered on 18 May 2012, 02:45 PM
That Worked ! Thanks so much for the help. 
0
Rajendra
Top achievements
Rank 1
answered on 24 Aug 2012, 09:00 AM

When the data type is string or Float the value should be in text,  if Data type is Boolean, value should be in Checkbox. When It is Enum, value should be a comboBox. Please find the attached "requirment.png" for more detail.

 Please let me know, How do I achieve this ? 
*I am using Telerik:RadGrid 


0
Dimitrina
Telerik team
answered on 24 Aug 2012, 09:08 AM
Hi,

I noticed that you have opened three threads with the same question, please stick all the answers to the original thread you have opened.

Greetings,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
GridView
Asked by
gans
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
gans
Top achievements
Rank 1
Rajendra
Top achievements
Rank 1
Share this question
or