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

How To Hide CheckBox For Specific Rows

3 Answers 295 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Kiran
Top achievements
Rank 1
Kiran asked on 06 Sep 2010, 07:11 AM
Hi

I have a GridViewCheckBox column which is created dynamically at runtime. I need to hide the checkboxes for particular rows based on a condition. I have seen some samples using cell template in XAML but I did not find any sample to do it using code behind or which suits this scenario. Here is the code

GridViewCheckBoxColumn tempCheckBoxColumn;
           foreach (PermissionValue permissionValue in employeeRecords.FirstOrDefault().RolePermission)
           {
               tempCheckBoxColumn = new GridViewCheckBoxColumn()
               {
                   Header = permissionValue.PermissionTypeDescription
                   ,
                   UniqueName = permissionValue.PermissionTypeDescription
                   ,
                   DataMemberBinding = new Binding("RolePermission[" + i + "].Value") { Mode = BindingMode.TwoWay }
                   ,
                   DataType = typeof(bool                     
               };
               tempDataColumn.IsReadOnly = false;
               this.grid.Columns.Add(tempCheckBoxColumn);
               i++;
           }

I need to hide the checkbox for some rows based on permissionValue.IsVisible value.

Regards
Kiran

3 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 06 Sep 2010, 08:48 AM
Hi Kiran,

GridViewCheckBox should not be appropriate in this case. You should use the CellTemplateSelector property.
Here is the help topic and here the online demo.

Hope this helps.

Regards,
Veselin Vasilev
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
Kiran
Top achievements
Rank 1
answered on 06 Sep 2010, 02:25 PM
Hi

Samples provided here are in XAML side there is nothing like creating celltemplates in C#. I have used GridViewDataColumn

GridViewDataColumn tempDataColumn = new GridViewDataColumn();
 foreach (PermissionType permissionType in permissionController.PermissionsModel.PermissionTypes)
            {
                colIndex = (short)(permissionType.PermissionTypeID - 1);
                tempDataColumn = new GridViewDataColumn()
                {
                    UniqueName = permissionType.PermissionTypeDescription
                    ,
                    DataMemberBinding = new Binding("PermissionValues[" + colIndex + "].Value") { Mode = BindingMode.TwoWay }
                    ,
                    DataType = typeof(bool)
                };
                tempDataColumn.Header = permissionType.PermissionTypeDescription;
                tempDataColumn.IsReadOnly = false;
  
                FrameworkPermissions.Columns.Add(tempDataColumn);
            }

My problem is that how to i create celltempalte selector from codebehind. Can you share any sample which has celltemplates manipulated in codebehind.

Regards
Kiran
0
Veselin Vasilev
Telerik team
answered on 07 Sep 2010, 02:55 PM
Hello Kiran,

It is easy to use the CellTemplateSelector in code behind. What is not that trivial is creating a DataTemplate in C#. You can check this thread on how to do this.

The easier way would be to define two DataTemplates in XAML as resources - one of them will have a checkbox, the other will not. Then, you can set the CellTemplateSelector property of the GridViewDataColumn in code to point to your Cell Template Selector.

I have attached a sample project.


Kind regards,
Veselin Vasilev
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
Tags
GridView
Asked by
Kiran
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Kiran
Top achievements
Rank 1
Share this question
or