custom control with multiple data binds

G

Guest

Is it possible to for a custom control to have 2 properties bound to 2
different fields from the same ADO.NET datasource. I noticed when writing
updates to my datasource only 1 field or property from the control is written.

For example....

Custom control:

public class MyControl : Usercontrol
{
[Bindable(true)]
public String PropA
{ get { return valueA; } }

[Bindable(true)]
public String PropB
{ get { return valueB; } }
}

Form Code

this.customControl.DataBindings.Add(new System.Windows.Forms.Binding
("PropA", datasource, "FieldA", true));
this.customControl.DataBindings.Add(new
System.Windows.Forms.Binding("PropB", datasource, "FieldB", true));


Regards
 
J

Joanna Carter [TeamB]

"codoherty" <[email protected]> a écrit dans le message de
news: (e-mail address removed)...

| Is it possible to for a custom control to have 2 properties bound to 2
| different fields from the same ADO.NET datasource. I noticed when writing
| updates to my datasource only 1 field or property from the control is
written.

Any control can be bound to more than one field on the same object, simply
add one Binding for each property on the control to the respective field.

Joanna
 
G

Guest

Hi Joanna,

This is what I thought, but what I have noticed is during the datasource
update, if I update more than 1 field then only the first field is saved.
This is strange because the read operation loads all the fields in the
control properties.

To explain, I have created an address control (street, town, zip, country,
etc...) that I use in many places, I then want to bind the respective fields
to a customer, supplier, bank record etc...

The only problen is, I edit the full address and when writing the record
only the 1 altered field is written to the record? This to me seems strange,
or am I missing something?

Regards
 
G

Guest

Ok! It seems that you have to exit (lose focus) the custom control after each
field edit. Is there any way to combat this behaviour.
 
J

Joanna Carter [TeamB]

"codoherty" <[email protected]> a écrit dans le message de
news: (e-mail address removed)...

| Ok! It seems that you have to exit (lose focus) the custom control after
each
| field edit. Is there any way to combat this behaviour.

Well, I assume you are using more than one control to enter the values ?

If so, you need to connect the different bindings, one to each
"sub-control", to the relevant property.

Does this make any sense to you ? :)

Joanna
 
G

Guest

Hi Joanna,

I just figured this, and ya it works, and also makes sense.

Many Thanks
 
J

Joanna Carter [TeamB]

"codoherty" <[email protected]> a écrit dans le message de
news: (e-mail address removed)...

| I just figured this, and ya it works, and also makes sense.
|
| Many Thanks

You're welcome.

Joanna
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top