Databinding Textbox to Dataset (winforms)

A

Andrew

I'm seeing an interesting problem when binding a textbox to a dataset.
The binding works correctly and will display the value, and when the value
is changed in the textbox, the value in the dataset is also changed.
HOWEVER, the dataset.HasChanges() call comes back with false! Am I not
binding correctly? Here's the line i'm using to bind:

textbox1.DataBindings.Add("Text",dataset1.Tables[0],"field1");

I must be doing something right because the textbox get data, and when I
change it, it is reflected in the dataset.

One other note, if I add a datagrid to the form, and databind that to the
same dataset, and then modify the grid, the dataset data changes as well,
and the dataset.HasChanges() call correctly comes back as true.

Am I not binding the textbox correctly? Is this a bug?

TIA,
Andrew
 
A

Andrew

Problem solved. I was missing the following line which allows the dataset
to see the changes:

this.BindingContext[dataset1.Tables[0]].EndCurrentEdit();

After calling this, dataset1.HasChanges correctly comes back as true.

One additional note though. Just making this call will NOT work:

this.BindingContext[dataset1].EndCurrentEdit();

Hope this helps someone else out there...
Andrew
 

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