Programmatic databinding

G

Guest

C# VS2003

Hi, I'm trying to use the Binding context object & Currency manager to
navigate through a table.

I've set the databindings for a parent child relationship of a label &
datagrid in the form load. Navigation is via the parent (Family):


// simple bind to label in Form load
lblFamily.DataBindings.Add("Text",dsMaster,"Family.FamilyName");


// complex bind to datagrid. Member is relation object
dgFamilyMembers.DataSource = dsMaster;
dgFamilyMembers.DataMember = "Family.FamilyFamilyMember";

then I instantiate a binding context object & use it to create a currency
manager object. The Currency manager is declared outside the class so to be
able to be used in various navigation buttons:

// Form load
BindingContext bc = new BindingContext();
// Used to nav through Parent relation table
cm = (CurrencyManager)bc[dsMaster,"Family"];


// Click event handler of button
// Increment record by one in click event of next button
cm.Position++;

The first record comes up in the label & datagrid ok & diaplays accordingly
to the one to many relationship on startup, but the currency manager doesn't
increment the records when I use cm.Position++. Thid cm object is declared as
a global object. Why does it not increment the position of the Binding
context?

Any answers would be most appreciated.
Ant
 
C

Cor Ligthert [MVP]

Ant,

Mostly this goes wrong that somehow the bindingcontext is different from the
datasource, can you try this one. (To understand what the properties of
strongly typed dataset means is more and more difficult by the new
versions).

Can you try to change this one in advance
dgFamilyMembers.DataSource = dsMaster.Tables["Family"];
// dgFamilyMembers.DataMember = "Family.FamilyFamilyMember";

I hope this helps,

Cor
 
G

Guest

Hi Cor,

Much appreciate the reply. I worked it out myself though & it was quite
simple.

I was instantiating a new BindingContext & using it, instead of using the
current BindingContext holding the bindings.

i.e.
// This wouldn't work as it is a new BindingContext
Bindincontext bc = new BindingContext();

CurrencyManager cm = bc[myDs,"myTable"];


Thanks for the input though. Appreciate it.
Ant



Cor Ligthert said:
Ant,

Mostly this goes wrong that somehow the bindingcontext is different from the
datasource, can you try this one. (To understand what the properties of
strongly typed dataset means is more and more difficult by the new
versions).

Can you try to change this one in advance
dgFamilyMembers.DataSource = dsMaster.Tables["Family"];
// dgFamilyMembers.DataMember = "Family.FamilyFamilyMember";

I hope this helps,

Cor

Ant said:
C# VS2003

Hi, I'm trying to use the Binding context object & Currency manager to
navigate through a table.

I've set the databindings for a parent child relationship of a label &
datagrid in the form load. Navigation is via the parent (Family):


// simple bind to label in Form load
lblFamily.DataBindings.Add("Text",dsMaster,"Family.FamilyName");


// complex bind to datagrid. Member is relation object
dgFamilyMembers.DataSource = dsMaster;
dgFamilyMembers.DataMember = "Family.FamilyFamilyMember";

then I instantiate a binding context object & use it to create a currency
manager object. The Currency manager is declared outside the class so to
be
able to be used in various navigation buttons:

// Form load
BindingContext bc = new BindingContext();
// Used to nav through Parent relation table
cm = (CurrencyManager)bc[dsMaster,"Family"];


// Click event handler of button
// Increment record by one in click event of next button
cm.Position++;

The first record comes up in the label & datagrid ok & diaplays
accordingly
to the one to many relationship on startup, but the currency manager
doesn't
increment the records when I use cm.Position++. Thid cm object is declared
as
a global object. Why does it not increment the position of the Binding
context?

Any answers would be most appreciated.
Ant
 
C

Cor Ligthert [MVP]

doh,

strongly typed dataset means is more and more difficult by the new
versions).
because of the new versions (so there are more methods).

In 2.0 it is in my idea better, not worse.

Cor
 

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