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

[Solved] Grouping by column with enum binding

5 Answers 304 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Weverton
Top achievements
Rank 1
Weverton asked on 02 Jul 2009, 08:26 PM
Hi,

I have a GridView with a column who is binded to enum. When I group by this Column, the Grid show the value of enum (1, 2, 3, etc) instead of its value.

What can I do to solve this problem??

Thanks,

Weverton

5 Answers, 1 is accepted

Sort by
0
Accepted
Rossen Hristov
Telerik team
answered on 03 Jul 2009, 07:27 AM
Hi Weverton,

You must define the column that will show the enum and specify a "General" format string. This will display the enum name instead of its value. Here is how to do it:

<UserControl x:Class="Ticket224345_GroupByEnumColumn.Page" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
    xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView"
    <Grid x:Name="LayoutRoot" Background="White"
        <telerik:RadGridView Name="grid"  
                             AutoGenerateColumns="False"  
                             ColumnsWidthMode="Auto"
            <telerik:RadGridView.Columns> 
                <telerik:GridViewDataColumn HeaderText="Subject"  
                                            DataMemberBinding="{Binding Subject}" /> 
                <telerik:GridViewDataColumn HeaderText="Status"  
                                            DataMemberBinding="{Binding Status}" 
                                            DataFormatString="{}{0:g}" /> 
            </telerik:RadGridView.Columns> 
        </telerik:RadGridView> 
    </Grid> 
</UserControl> 
 

I have attached a small sample project that has everything set up. Please, let me know if you have any other questions.

Greetings,
Ross
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Joe
Top achievements
Rank 1
answered on 21 Jul 2009, 11:45 PM
I've tested this with your latest dll version 2009.2.720.1020 on SL2 and this does not work. It seems to have been broken with the latest release. Grouping by the column will show the enum integer value instead of the string.

Please advise. Thanks.
0
Rossen Hristov
Telerik team
answered on 23 Jul 2009, 01:27 PM
Hello Joe,

I have prepared a sample project with the version that you mentioned. On my end everything works as expected. When I group the football players by their Position I get 4 groups with the following headers: GK, DF, MF, and FW. The Position column is bound to enum.

Can you please tell me how to reproduce the behavior you are experiencing. I have attached the sample project.

Greetings,
Ross
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Joe
Top achievements
Rank 1
answered on 23 Jul 2009, 03:26 PM
Thank you for your reply. I tried opening your project and ran into a VS error. The shortened msg is 'The imported project "C:\Program Files\MSBuild\Microsoft\Silverlight\v3.0\Microsoft.Silverlight.Csharp.targets" was not found.' Seems to me it is referencing SL3 somehow.
So I took your code and plugged it into a new test project. After getting it to build, I still see the problem with grouping where it shows the integer values in the grouped header.
There is something I noticed. In the code you sent me, you did not include the below property setting for the position column.

DataFormatString

 

="{}{0:g}" 

 

So the values in the column itself showed the integer values. I added the DataFormatString to the xaml. However, when grouped, it still does not show the position enum string values.

I double checked to see that I am referencing the same dll version that you had in your sample and that looks to be the same. I am not sure what else can be the problem. I can't attach my project to this so I can't send you what I have. Perhaps it has something to do with SL3 reference that I mentioned in the beginning of this msg.

0
Rossen Hristov
Telerik team
answered on 27 Jul 2009, 09:01 AM
Hi Joe,

You are right. I have made a mistake and tested with SL3. It seems that this issue exists in the SL2 build, but since we want to concentrate on the new SL3 we will no longer maintain the SL2 versions. So my advice is to upgrade to our latest SL3 bits, which should resolve the issue as demonstrated in the sample project that I have created. Please let us know if you are still experiencing the same problem when you migrate to SL3.

Greetings,
Ross
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
GridView
Asked by
Weverton
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Joe
Top achievements
Rank 1
Share this question
or