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

Cell style template

4 Answers 131 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Goran
Top achievements
Rank 1
Goran asked on 10 Aug 2012, 02:18 PM
I am having a grid inside a grid scenario, I am going to show code for hierarchical template, which is cut to essential parts (and showing only two columns):

<telerik:RadGridView.HierarchyChildTemplate>
    <DataTemplate>
        <telerik:RadGridView AutoGenerateColumns="False"
                               IsSynchronizedWithCurrentItem="True"
                               ItemsSource="{Binding Items}"
                               RowStyleSelector="{StaticResource CycleActivityProductRowStyleSelector}">
            <telerik:RadGridView.Columns>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Speed}"
                           Header="Speed" />
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Output}"
                           Header="{Binding Output}" />
            </telerik:RadGridView.Columns>
        </telerik:RadGridView>
    </DataTemplate>
</telerik:RadGridView.HierarchyChildTemplate>

This grid is binded to a collection of items, which is a property on the entiy from the main grid (remember this is a grid inside hierarchical template). Each item has a property Type. Based on the type I am painting the row using RowStyleSelector. So far no problems. Now I need to have different cell style / template based  on the item Type.

Item name:             Speed:         Output:
Item 1                      50                1000            Type.A
Item 2                                            300            Type.B
Item 3                      25                  600            Type.A

As you can see, I do not want even show the value for Speed column for Type.B (currently it is showing 0). Also, Speed column is editable for TypeA items, should not be for Type.B items

What is the cleanest / best way to achieve this?

Regards,
Goran

4 Answers, 1 is accepted

Sort by
0
Goran
Top achievements
Rank 1
answered on 10 Aug 2012, 02:55 PM
Hi,

in addition to above, why do you have IsEnabled on GridViewDataColumn? So far what I see it doesn;t work at all. There is IsReadOnly, but that will only deny / allow editing, but visually ediable / read-onlly columns / cells would still look the same.

When you apply to a particular cell IsEnabled = false, then we get a greyish background that tells us it is disabled. How to achieve the same on column level?
0
Maya
Telerik team
answered on 14 Aug 2012, 07:34 AM
Hello Goran,

If you want a particular item/ cell to be editable or not, you can work with IsReadOnlyBinding. As for displaying or not a value in the cell, you can create your own IValueConverter implementation and convert it to empty string for example.
On a side note, in WPF GridViewColumn inherits FrameworkContentElement, which inherits ContentElement, where the IsEnabled property comes from. However, it is used at column-level in RadGridView. The way to go if you want to disable a column is to set this property for the cells. Check out this article for a reference.
 

Greetings,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Goran
Top achievements
Rank 1
answered on 14 Aug 2012, 11:40 AM
Hi Maya,

"On a side note, in WPF GridViewColumn inherits FrameworkContentElement, which inherits ContentElement, where the IsEnabled property comes from. "

So does GridViewCell (UiElement), but it seems that IsEnabled is working there. So, how do we know where it works and where it doesn't? If your documentation is aiming to be helpful, it would list something like this:

GridViewDataColumn.IsEnabled:
Not used. This is a dependency property. (Inherited from ContentElement.).

GridViewCell.IsEnabled
Gets or sets a value indicating whether this element is enabled in the user interface (UI). This is a dependency property. (Inherited from UIElement.).

As for the IsReadOnlyBinding I have read about it, but I needed to emhasize difference between the editable and read-only cell, so I was leaning to making it disabled. So, I achieved that with StyleSelector, where I could apply rule for making it disabled, and just set container to disabled. I am still not sure which is a better way performance wise, I am going to leave that for later, if I see any problems in performance. I doubt I can use IValueConverter since I need to have access to object hierarchy, and possibly VIewModel's properties to determine which cell should be read-only. IMultiValueConverter is possible way to go, but I am not sure which is better way for performance. And since the disabled style is quite "pale" in coiors, so the visibility is greatly reduced in increased-light environment, I will need to create a custom style, so probably the StyleSelector is the best way to go.

By the way, the link you gave to disable column / cell doesn't contain much information about how to actually do it.. It just says it can be done and points to an article to read, without specifying a link, so its not much informative. But, I think I stumbled upon this article few days ago, if I remember well it used code behind to loop through all cells and disables them.

Regards,
Goran
0
Accepted
Maya
Telerik team
answered on 20 Aug 2012, 06:38 AM
Hello Goran,

Firstly, thank you for you feedback on the documentation. We will improve it so that it is more informative and contains more examples on it.
Considering the usage of StyleSelector in your case, there should be no performance degradation and it would be the way to go here.
Still, let me know in case you meet any difficulties with the implementation. 

All the best,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

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