Benutzer:MovGP0/WinForms/DataBinding
Zur Navigation springen
Zur Suche springen
MovGP0 | Über mich | Hilfen | Artikel | Weblinks | Literatur | Zitate | Notizen | Programmierung | MSCert | Physik |
ComboBox[Bearbeiten | Quelltext bearbeiten]
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[Bearbeiten | Quelltext bearbeiten]
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";
}
|