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

Need to change CheckBox display for AutoGenerated Grid Cell

6 Answers 134 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Kathleen
Top achievements
Rank 1
Kathleen asked on 13 Feb 2013, 09:47 PM
I have an entity, its read only to the grid and it has a boolean property:  IsActive?

The grid is AutoGenerated=true so we don't have defined columns in the XAML.

In the grid (using the windows 7 theme) this value appears as a disabled, faint grey checkbox that is aligned left.

I need to be able to override this and lose the disabled state, but still be read only.
I need to be able to override this and align it properly to the center.
I need to be able to in the future, override this and replace the check box with "Yes/No"

Thanks

6 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 14 Feb 2013, 07:30 AM
Hi,

 You can modify auto-generated columns using AutoGeneratingColumn event. In your case for example you can assign new CellTemplate for desired column or you can replace desired column with other column or your own custom column.

Kind regards,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Kathleen
Top achievements
Rank 1
answered on 14 Feb 2013, 03:57 PM
Thank you but after several hours of trial and error I really need to know a bit more how to do this.

I've tried a conditional style selector, I've tried just a straight data template.

My primary issue is I cannot determine the proper binding statement to use the Bound Value to the cell (The Boolean Value).

For example, in this code, the CheckedValueConverter gets the entire entity on the row.  I don't know which column I am on in order to bind to the right entity property.

Ideally if I could I would just use a visibility converter on the checked path and use only one template instead of a selector, but again I don't know how to get to the cell's original property value.

 <DataTemplate x:Key="ReadOnlyCheckedGrid">        
        <Grid HorizontalAlignment="Center" Height="13" VerticalAlignment="Center" Width="13">
            <Border BorderBrush="Black" BorderThickness="1 1 1 1">
                <Border BorderBrush="#FFEEEEEE" BorderThickness="1 1 1 1">
                    <Border BorderBrush="#FFB9B9B9" BorderThickness="1 1 1 1" Background="#FFE0E0E0">
                        <Grid Margin="0" x:Name="CheckBoxGrid">                     
                            <Path x:Name="CheckedPath" Data="M32.376187,77.162509 L35.056467,80.095277 40.075451,70.02144" HorizontalAlignment="Center"
                                  Margin="0" Stretch="Fill" Stroke="Black" StrokeThickness="1.5" Visibility="Visible" VerticalAlignment="Center"/>
                        </Grid>
                    </Border>
                </Border>
            </Border>
        </Grid> 
    </DataTemplate>
    <DataTemplate x:Key="ReadOnlyUnCheckedGrid">
        <Grid HorizontalAlignment="Center" Height="13" VerticalAlignment="Center" Width="13">
            <Border BorderBrush="Black" BorderThickness="1 1 1 1">
                <Border BorderBrush="#FFEEEEEE" BorderThickness="1 1 1 1">
                    <Border BorderBrush="#FFB9B9B9" BorderThickness="1 1 1 1" Background="#FFE0E0E0">
                    
                    </Border>
                </Border>
            </Border>
        </Grid>
    </DataTemplate>
    <Converters:CheckedValueConverter x:Key="CheckedValueConverter"/>
    <Presentation:ConditionalDataTemplateSelector x:Key="CheckedGridTemplateSelector" ConditionConverter="{StaticResource CheckedValueConverter}">
        <Presentation:ConditionalDataTemplateSelector.Rules>
            <Presentation:ConditionalDataTemplateRule DataTemplate="{StaticResource ReadOnlyCheckedGrid}">
                <Presentation:ConditionalDataTemplateRule.Value>
                    <sys:Boolean>True</sys:Boolean>
                </Presentation:ConditionalDataTemplateRule.Value>
            </Presentation:ConditionalDataTemplateRule>
            <Presentation:ConditionalDataTemplateRule DataTemplate="{StaticResource ReadOnlyUnCheckedGrid}">
                <Presentation:ConditionalDataTemplateRule.Value>
                    <sys:Boolean>False</sys:Boolean>
                </Presentation:ConditionalDataTemplateRule.Value>
            </Presentation:ConditionalDataTemplateRule>
        </Presentation:ConditionalDataTemplateSelector.Rules>
    </Presentation:ConditionalDataTemplateSelector>


  if (e.ItemPropertyInfo.PropertyType == typeof(Boolean) || e.ItemPropertyInfo.PropertyType == typeof(Nullable<Boolean>) || e.ItemPropertyInfo.PropertyType == typeof(bool?) 
                    || e.ItemPropertyInfo.PropertyType == typeof(bool))
                {
                    e.Column.CellTemplateSelector = Application.Current.Resources["CheckedGridTemplateSelector"] as ConditionalDataTemplateSelector;
                }

0
Vlad
Telerik team
answered on 19 Feb 2013, 09:34 AM
Hi,

 If you do not know the property name you can use the Value property of GridViewCell for binding. 

Greetings,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Kathleen
Top achievements
Rank 1
answered on 21 Feb 2013, 12:49 AM
I'm sorry, but as I indicated in my example, the entity I'm getting is the bound entity, not the gridcellview.

Do you have any examples of how to do this with autogenerated columns? 
0
Kathleen
Top achievements
Rank 1
answered on 17 Apr 2013, 03:29 AM
Still need an answer for this:

Using AutoGenerateColumns, with an entity that is read only and has a boolean property, what can I do to update the style?

I've been trying around Blend and cannot find it. 
The disabled Checkbox is hard for users to read.
Need to remove the disabled state.


Entity Client
Property bool IsActive

Entity Location
Property bool IsPrimary

Entity Phone
Property bool IsPrimary
0
Yoan
Telerik team
answered on 19 Apr 2013, 12:25 PM
Hello,

Generally, to achieve this  when autogenerating columns , the approach would be as follows : 

1. Define your template in a static resource . 
2. Handle the AutogeneratingColumn event of RadGridView.
3. Inside the event handler - check the DataType  and set the  template to the column , reading it from the static resource. 

All the best,
Yoan
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
GridView
Asked by
Kathleen
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Kathleen
Top achievements
Rank 1
Yoan
Telerik team
Share this question
or