开发者

How to properly bind to a child object?

开发者 https://www.devze.com 2023-01-15 22:07 出处:网络
I have an object Proposal which has a property called CurrentAgency of Agency which in turn has AgencyID, Name, etc...something like this:

I have an object Proposal which has a property called CurrentAgency of Agency which in turn has AgencyID, Name, etc...something like this:

Proposal
    CurrentAgency
        AgencyID
        Name
        Address
        etc...

In my UI, I have a combobox that lists all available Agencies. I have bound it like this:

private BindingSource bndProposal = new BindingSource();
bndProposal.DataSource = typeof(Model.Proposal);
lkpAgency.DataBindings.Add("EditValue", bndProposal, "CurrentAgency.AgencyID");
lkpAgency.Properties.DataSource = FusionLookups.LookupAgencies;
lkpAgency.Properties.DisplayMember = "Name";
lkpAgency.Properties.ValueMember = "ID";

And this works well enough. If the user changes the agency, Proposal.CurrentAgency.AgencyID is automatically updated. However, the problem is that the rest of the properties of the CurrentAgency object are not updated.

What are some of the patterns that are used to handle this kind of situation while not gunking up the code with junk? Do I handing the Format event on the Binding object? Any ideas for clean impl开发者_运维技巧ementation are welcome.


Have you tried the following?

private BindingSource bndProposal = new BindingSource();
bndProposal.DataSource = typeof(Model.Proposal);
lkpAgency.DataBindings.Add("EditValue", bndProposal, "CurrentAgency");
lkpAgency.Properties.DataSource = FusionLookups.LookupAgencies;
lkpAgency.Properties.DisplayMember = "Name";
lkpAgency.Properties.ValueMember = null;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号