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

Filter for enum values don't use specified converters in drop down (equals, not equals)

4 Answers 295 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Christian
Top achievements
Rank 1
Christian asked on 17 Mar 2011, 02:17 PM
Hello everyone,

we have a simple RadGridView with one column bound to a enum property of a view model with a converter:

<telerik:GridViewDataColumn DataMemberBinding="{Binding SomeValue, Converter={StaticResource TestConverter}}" />

ViewModel:

public class TestViewModel {
    public TestEnum SomeValue { get; set; }
}
public enum TestEnum {
    A,
    B,
    C
}

And the converter code simply translates the bound enum value to a more readable text:

public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) {
    var test = (TestEnum)value;
    switch (test) {
        case TestEnum.A: return "TestEnum with Value A";
        case TestEnum.B: return "TestEnum with Value B";
        case TestEnum.C: return "TestEnum with Value C";
    }
    throw new NotImplementedException();
}

The grid is rendered correctly ("TestEnum with Value A"), but all drop downs located in the extended filter are using the raw values ("A", "B", "C") of our enum and not the transformed values for our converter.

Is there a way to work around this issue (beside translating the values prior to binding, i.e. coding a seconding property and doing the translation without a converter)?

Version: RadControls for WPF Q1 2011

FYI - I can provide a simple c# test project in order to reproduce the issue if needed.

Your sincerely,

Christian

4 Answers, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 21 Mar 2011, 10:41 AM
Hello Christian,

Unfortunately, the combo can't respect the IValueConverter.

But...

If you add a Description attribute to each Enum value it will be respected by the combo. So if you add Descriptions with the same strings as the ones in the value converter you should see them in the combo.

You can even re-write your converter to read the Description of each enum value and return its value. In this way you will have the string only at one place, i.e. in the Description attribute.

I hope this helps.

Kind regards,
Ross
the Telerik team
0
Christian
Top achievements
Rank 1
answered on 22 Mar 2011, 09:14 AM
Hi Ross,

thanks! But that's not an option (at least in that case), because our converter is a language converter, which means it's runtime depend which value is returned:

<telerik:GridViewDataColumn  DataMemberBinding="{Binding Type, Converter={StaticResource LanguageConverter}" />

LanguageConverter takes the value of "Type" and looks it up in a .NET resource file depending on the current culture of the user. As far as I know a DescriptionAttribute(string text) is only a compile time attribute and thus cannot be changed by the runtime :-(.

Christian
0
Accepted
Rossen Hristov
Telerik team
answered on 22 Mar 2011, 10:27 AM
Hi Christian,

Then your only option would be to build your very own filtering control and do anything that you want inside it.

I hope this helps.

Kind regards,
Ross
the Telerik team
0
Christian
Top achievements
Rank 1
answered on 22 Mar 2011, 03:15 PM
Hi Ross,

oh cool, didn't think of that!

But I guess I stick to translating the property in my viewmodel and then binding to an already translated value.

Christian
Tags
GridView
Asked by
Christian
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Christian
Top achievements
Rank 1
Share this question
or