Hi @ll,
I need your help. After searching the internet for several hours I have
no solution for my problem.
I have an enum property which I bind to a GridViewComboBoxColumn
using the following xaml code:
<telerik:GridViewComboBoxColumn ItemsSourceBinding="{Binding Options}" DataMemberBinding="{Binding Position}" DisplayMemberPath="Value" SelectedValueMemberPath="Key"/>
Options is a property which maps the enum value to a string:
public enum Pos{ A, B, C}public class DisplayObject<T>{ private readonly T key; private readonly string val; public DisplayObject(T key, string val) { this.key = key; this.val = val; } public T Key => this.key; public string Value => this.val;}
public IEnumerable<DisplayObject<Pos>> Options{ get { yield return new DisplayObject<Pos>(Pos.A, "HUGO"); yield return new DisplayObject<Pos>(Pos.B, "EGON"); yield return new DisplayObject<Pos>(Pos.C, "WILLI"); }}
Grid works fine. But there are some problems with the FilteringControl.
I want the FilteringControl to uses the DisplayMemberPath to display
the DistinctValues and ComboBox Options.
Can anyone help me solving my problem?
public class Item : INotifyPropertyChanged{ private Pos pos; private string name; public Item(string name, Pos pos) { this.name = name; this.pos = pos; } public string Name { get { return this.name; } } public Pos Position { get { return this.pos; } set { if (this.pos == value) { return; } this.pos = value; this.OnPropertyChanged(nameof(this.Position)); } } public IEnumerable<DisplayObject<Pos>> Options { get { yield return new DisplayObject<Pos>(Pos.A, "HUGO"); yield return new DisplayObject<Pos>(Pos.B, "EGON"); yield return new DisplayObject<Pos>(Pos.C, "WILLI"); } } public event PropertyChangedEventHandler PropertyChanged; [NotifyPropertyChangedInvocator] protected virtual void OnPropertyChanged(string propertyName) { this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); }}<Window x:Class="ChangeDefaultFilterOperator.MainWindow" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" xmlns:my="clr-namespace:ChangeDefaultFilterOperator" Title="MainWindow" Height="700" Width="700"> <Window.Resources> <my:MyViewModel x:Key="MyViewModel"/> </Window.Resources> <Grid DataContext="{StaticResource MyViewModel}"> <telerik:RadGridView ItemsSource="{Binding Items}" AutoGenerateColumns="False" Margin="5"> <telerik:RadGridView.Columns> <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}"/> <telerik:GridViewComboBoxColumn ItemsSourceBinding="{Binding Options}" DataMemberBinding="{Binding Position}" DisplayMemberPath="Value" SelectedValueMemberPath="Key"/> </telerik:RadGridView.Columns> </telerik:RadGridView> </Grid></Window>public class MyViewModel{ private readonly ObservableCollection<Item> items; public MyViewModel() { this.items = new ObservableCollection<Item> { new Item("AAA", Pos.A), new Item("BBB", Pos.B), new Item("CCC", Pos.C) }; } public ObservableCollection<Item> Items { get { return this.items; } }}