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

GridView Filter

3 Answers 38 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Amit Patel
Top achievements
Rank 1
Amit Patel asked on 24 Jun 2010, 03:21 PM

GridView Filter

I would like to display customize name when binding enum property to a column. Right now it would display the Enum Name e.g. “TimeUnit’  as opposed to “Time Unit” with space.  Is there a way to achieve this without too much customization to grid filter?

 Lets say i have Enum and Class like listed below that i would use for binding to GridView, and would expect filter to show "Time Unit" & Work Unit.

public enum Unit

                {

                                [Display("Time Unit")]

                                TimeUnit,

                                [Display("Time Unit")]

                                WorkUnit

                }

 

Public class MyClass

{

                Public Unit {get; set;}

}

3 Answers, 1 is accepted

Sort by
0
Milan
Telerik team
answered on 25 Jun 2010, 01:23 PM
Hi Amit Patel,

You could do this by defining a custom attribute and a converter which will read the custom attribute and show the predefined display text.

I have attached a sample project which demonstrates this approach. 


All the best,
Milan
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
Amit Patel
Top achievements
Rank 1
answered on 25 Jun 2010, 04:31 PM
Milan,

Thanks for the quick response! The solution you provided works great when binding to GridViewDataColumn; however, it does not work when binding to GridViewComboBoxColumn using a converter. The Drop down box show a blank value instead of showing the predefined values.  Please let me know if you are able to show the values in drop down box.

Thanks,
Amit
0
Milan
Telerik team
answered on 30 Jun 2010, 09:24 PM
Hi Amit Patel,

Using this with combo columns is a bit more tricky - you should utilize the ItemTemplate property of the combo column:

<telerik:GridViewComboBoxColumn DataMemberBinding="{Binding UnitType}">
    <telerik:GridViewComboBoxColumn.ItemTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding Converter={StaticResource enumConverter}}"/>
        </DataTemplate>
    </telerik:GridViewComboBoxColumn.ItemTemplate>
</telerik:GridViewComboBoxColumn>


Sincerely yours,
Milan
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
Menu
Asked by
Amit Patel
Top achievements
Rank 1
Answers by
Milan
Telerik team
Amit Patel
Top achievements
Rank 1
Share this question
or