Exemplo n.º 1
0
 public static void Bind <TBinding, TSource, TProperty>(
     this ComboBox comboBox,
     TBinding item,
     Expression <Func <TBinding, TProperty> > member, ComboBoxSource.ComboBoxBinding <TSource> binding)
 {
     BindSource(comboBox, binding);
     BindSelectedItem(comboBox, item, member, binding);
 }
Exemplo n.º 2
0
 public Bind <TBinding> For <TSource, TProperty>(
     ComboBox comboBox,
     Expression <Func <TBinding, TProperty> > member,
     ComboBoxSource.ComboBoxBinding <TSource> binding)
 {
     comboBox.Bind(_item, member, binding);
     return(this);
 }
Exemplo n.º 3
0
 private static void BindSelectedItem <TBinding, TSource, TProperty>(ComboBox comboBox,
                                                                     TBinding item,
                                                                     Expression <Func <TBinding, TProperty> > member,
                                                                     ComboBoxSource.ComboBoxBinding <TSource> binding)
 {
     comboBox.DataBindings.Add(nameof(ComboBox.SelectedItem), item, ReflectionUtils.GetPropertyName(member));
     comboBox.SetDefault(binding.DefaultValue);
     comboBox.SelectionChangeCommitted += (sender, e) => comboBox.DataBindings[nameof(ComboBox.SelectedItem)].WriteValue();
     (comboBox.DataSource as IBindingList).ListChanged += (sender, e) =>
     {
         var value = ReflectionUtils.GetValue(item, member);
         if (value == null)
         {
             comboBox.SetDefault(binding.DefaultValue);
         }
     };
 }
Exemplo n.º 4
0
 private static void BindSource <TSource>(ComboBox comboBox, ComboBoxSource.ComboBoxBinding <TSource> binding)
 {
     comboBox.DataSource    = binding.Source;
     comboBox.DisplayMember = binding.DisplayMember;
     comboBox.ValueMember   = binding.ValueMember;
 }