Benutzer:MovGP0/WinForms/DataBinding
aus Wikipedia, der freien Enzyklopädie
< Benutzer:MovGP0 | WinForms
Dies ist die aktuelle Version dieser Seite, zuletzt bearbeitet am 20. Januar 2015 um 10:33 Uhr durch imported>MovGP0(77247) (→ComboBox).
MovGP0 | Über mich | Hilfen | Artikel | Weblinks | Literatur | Zitate | Notizen | Programmierung | MSCert | Physik |
ComboBox
MyDropDown.DataBindings.Add(@"SelectedValue", ViewModel, @"MyProperty", false, DataSourceUpdateMode.OnPropertyChanged);
MyDropDown.DataBindings.Add(@"Enabled", ViewModel, @"IsMyPropertyEnabled", false, DataSourceUpdateMode.OnPropertyChanged);
BindDropDownDataSource();
// observe changes and rebind when something changes
var subscription = ViewModel
.Where(args => args.PropertyName == "MyProperty")
.Subscribe(args => BindDropDownDataSource());
_subscriptions.Add(subscription); // remember to dispose subscriptions
private void BindDropDownDataSource()
{
MyDropDown.DataSource = ViewModel.MyProperty;
MyDropDown.DisplayMember = @"DisplayName";
MyDropDown.ValueMember = @"Id";
}
DevExpress LookupEdit
MyDropDown.DataBindings.Add(@"EditValue", ViewModel, @"MyProperty", false, DataSourceUpdateMode.OnPropertyChanged); // EditValue instead of SelectedValue
MyDropDown.DataBindings.Add(@"Enabled", ViewModel, @"IsMyPropertyEnabled", false, DataSourceUpdateMode.OnPropertyChanged);
BindDropDownDataSource();
// observe changes and rebind when something changes
var subscription = ViewModel
.Where(args => args.PropertyName == "MyProperty")
.Subscribe(args => BindDropDownDataSource());
_subscriptions.Add(subscription); // remember to dispose subscriptions
private void BindDropDownDataSource()
{
// use the Properties-Property
MyDropDown.Properties.DataSource = ViewModel.MyProperty;
MyDropDown.Properties.DisplayMember = @"DisplayName";
MyDropDown.Properties.ValueMember = @"Id";
}
|