Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Binding ComboBox to enum
Message
From
20/12/2012 06:37:30
 
 
General information
Forum:
ASP.NET
Category:
Windows Presentation Foundation (WPF)
Miscellaneous
Thread ID:
01559922
Message ID:
01560254
Views:
54
>>Hmm...
>>
>>This is proving to be more trouble than it's worth. Maybe I'll go back to using a table rather than an enum. At least that's easy.
>>
>>What is happening is that the combo is populated with the enum values, but it does not display the appropriate item from the list when I select an existing record. Is there some sort of code that I'll have to add in to cause it refresh or display the correct one?
>
>Again it should just work providing the DC supports INotifyPropertyChanged (and the value in the record is a valid enum value). If you are using MM I don't know how that fits in. Here's a simple working example based on the XAML I posted previously:
using System.ComponentModel;
>using System.Windows;
>
>namespace WpfApplication1
>{
>  public partial class MainWindow : Window, INotifyPropertyChanged
>  {
>    public MainWindow()
>    {
>      InitializeComponent();
>      SelectedRate = RateType.Standard;
>      DataContext = this;
>    }
>
>    private void Button_Click_1(object sender, RoutedEventArgs e)
>    {
>      SelectedRate = RateType.ZipX;
>    }
>
>    private RateType _selectedRate;
>    public RateType SelectedRate
>    {
>      get { return _selectedRate; }
>      set{_selectedRate = value; OnPropertyChanged("SelectedRate");
>      }
>    }
>
>    public event PropertyChangedEventHandler PropertyChanged;
>    protected void OnPropertyChanged(string name)
>    {
>      if (PropertyChanged != null)
>      {
>        PropertyChanged(this, new PropertyChangedEventArgs(name));
>      }
>    }
>  }
>
>  public enum RateType : int
>  {
>    Standard = 1,
>    Mail = 2,
>    ZipX = 3
>  }
>}
I know there's a learning curve but I'd advise against using a table - enums are far safer and easier to code against. Bear in mind that the problem you are having now is not related to the ObjectDataProvider - just a straight forward binding problem.....

Thanks, I'll look at this again today, hopefully. At first glance it looks like you have to code it to display the correct one? Or should the binding automatically force it do display the correct one?
Frank.

Frank Cazabon
Samaan Systems Ltd.
www.samaansystems.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform