What's the point of Simple Data Binding?

J

Jow Blow

Hello All,

In two different books, Simple Data Binding to a control is explained
with an example of a TextBox where the data is initialized with an
array.

For example a class is defined as such:

public class Vendor
{
private string vendorName;
public string VendorName
{
get
{
return vendorName;
}
set
{
vendorName = value;
}
}

public Vendor(string strVendorName)
{
VendorName = strVendorName;
}
}
}

A TextBox is placed on the main form Form1 with the following code:

public Vendor[] aVendors;

private void Form1_Load(object sender, System.EventArgs e)
{
this.aVendors = new Vendor[3];
aVendors[0] = new Vendor("Microsoft");
aVendors[1] = new Vendor("Praxis");
aVendors[2] = new Vendor("Rational");


txtVendor.DataBindings.Add("Text",aVendors,"VendorName");
}

where txtVendor is the name of the TextBox.

My question now is what else can you do with this? What's the point?
Is there some utilitarian advantage here that I am not seeing?

Neither of the texts expands on this. They both go into Complex Data
Binding which is a different animal. FYI,I am coming from the MFC VC++
world is that means anything.

Thanks,
Joe

I can also be reached at:
filter1_at_digitalchickenDOTnetNOSPAM
 
C

ClayB [Syncfusion]

Try adding a button to your form with this button handler.

private void button1_Click(object sender, System.EventArgs e)
{
BindingManagerBase bmb =
this.BindingContext[this.aVendors];
bmb.Position = (bmb.Position + 1) % bmb.Count;
}

Then imagine your vendor class has 50 public properties, and you want to
show 10 of them in labels or textboxes on a form so you can edit them. You
could then use the BindingManagerBase to move the 'current' vendor back and
forth. This effectively lets you page through all the vendor' properties
with just Next and Previous buttons.

==========================
Clay Burch, .NET MVP

Visit www.syncfusion.com for the coolest tools
 
J

Jow Blow

Clay,

Thanks for your response.

I can see your point.

In VC++ MFC, one would use the DDX, the UpdateData() and so forth
function in order to pass data from variables to controls or vice
verse. The methodology in .NET doesn't seem to be as explicit... at
least it isn't to me.

I'm not seeing explicit ways to (as per the previous example):
pass data from the control back to sVendors once data in aVendors has
changed or the form is closing, AND
refresh the control(s) once the base data has changed.

Neither of the two books I have cite an example.

Also neither show where currencymanager is used explicitly. Both speak
of CurrencyManager in comments but show the Position property of
BingingContext being used. As far as I can tell from the .NET
documentation Position is being called from a BindingContext. I see no
example where CurrencyManager is being called and I dont see an
instance of it as a member of form classes or controlcontainers or
bindingcontexts. I must be missing something.

Thanks Clay...

Joe
 
J

Jow Blow

I'm not seeing explicit ways to (as per the previous example):
pass data from the control back to sVendors once data in aVendors has
changed or the form is closing, AND
refresh the control(s) once the base data has changed.


CORRECTION. That should be aVendors and not sVendors.

Joe
 

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