PC Review


Reply
Thread Tools Rate Thread

Databinding Textbox to Dataset (winforms)

 
 
Andrew
Guest
Posts: n/a
 
      12th Nov 2003
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
 
Reply With Quote
 
 
 
 
Andrew
Guest
Posts: n/a
 
      12th Nov 2003
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

On Wed, 12 Nov 2003 08:44:33 +0000, Andrew wrote:

> 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


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Winforms] Databinding and a Trigger... EŽ!k \\/!sser Microsoft ADO .NET 1 29th May 2009 02:22 PM
Two-Way databinding in WinForms =?Utf-8?B?VG9tYSBNYXJpbm92?= Microsoft Dot NET 2 18th Apr 2006 11:47 AM
databinding in winforms to listbox Martin Microsoft Dot NET Framework Forms 2 29th Jun 2004 07:45 AM
Sample code covering databinding for TextBox control on WinForms =?Utf-8?B?c2pAb25saW5lLm9yZw==?= Microsoft Dot NET 1 10th Mar 2004 03:46 PM
DataSet Field Value to textbox without databinding Eddy Balan Microsoft VB .NET 2 29th Oct 2003 12:48 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:08 PM.