By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,081 Members | 2,118 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,081 IT Pros & Developers. It's quick & easy.

Data Binding GUI refresh

P: n/a
Hi Team

this may be a newbie question. I have searched the discussions before
posting:

I'd like to re-use a form instance to edit record details. My data binding
(a DataTable bound to TextBoxes) works fine the first time round. I can see,
edit and update the details from my form, then close the form.

I then like to select and refill the datatable with a different record (new
query) and open the same form again. I send the new datatable to the
(existing yet invisible) form before using ShowDialog. I have confirmed that
the new datatable has the new record data in it, consists of only one row and
has indeed arrived at the form. I clear the data bindings of all the
textboxes and re-set them with the new datatable. (I have also tried to
ResetBindings() for the form at this point.)

But no matter what I try in terms of Update(), Refresh(), Invalidate() the
textboxes stubbornly display the data from the original binding! I have
tried to update before and after the form has appeared. I have also tried to
keep the original binding but clear and then re-fill the datatable with a new
record from the database, all to no avail. I'm at my wits end.

Of course it works just fine, when I re-instantiate a new form each time I
wish to edit a new record, but I reckon that is inefficient; and also I'd
like to find out how this binding mechanism really works.

Any ideas are much appreciated.

Thanks
Matthias
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Matthias:

Without seeing your code, I do not if the following KB article applies to
your situation or not, however, I thought I would pass it along.

http://support.microsoft.com/default...b;en-us;812919

--
David Lloyd
MCSD .NET
http://LemingtonConsulting.com

This response is supplied "as is" without any representations or warranties.
"Matthias" <Ma******@discussions.microsoft.com> wrote in message
news:5B**********************************@microsof t.com...
Hi Team

this may be a newbie question. I have searched the discussions before
posting:

I'd like to re-use a form instance to edit record details. My data binding
(a DataTable bound to TextBoxes) works fine the first time round. I can
see,
edit and update the details from my form, then close the form.

I then like to select and refill the datatable with a different record (new
query) and open the same form again. I send the new datatable to the
(existing yet invisible) form before using ShowDialog. I have confirmed
that
the new datatable has the new record data in it, consists of only one row
and
has indeed arrived at the form. I clear the data bindings of all the
textboxes and re-set them with the new datatable. (I have also tried to
ResetBindings() for the form at this point.)

But no matter what I try in terms of Update(), Refresh(), Invalidate() the
textboxes stubbornly display the data from the original binding! I have
tried to update before and after the form has appeared. I have also tried
to
keep the original binding but clear and then re-fill the datatable with a
new
record from the database, all to no avail. I'm at my wits end.

Of course it works just fine, when I re-instantiate a new form each time I
wish to edit a new record, but I reckon that is inefficient; and also I'd
like to find out how this binding mechanism really works.

Any ideas are much appreciated.

Thanks
Matthias
Nov 21 '05 #2

P: n/a
Thanks David!

I studied the link carefully and I'm amazed that there are .NET bugs like
this still not remedied. But it turned out not to be my problem. I have
experimented for a few more hours with this problem, basically trying to
write a simple piece of test code that I could forward to you and the group.
When trying to write this simple piece of code I noticed that everything just
worked fine. So I had a version that worked and one that didn't, and after
narrowing it down I found my mistake and possibly something like another .NET
bug? What took me so long is that the problem (the form displaying the
original data instead of the new data bound) seemed to have nothing to do
with my mistake. Here it goes:

In the Load method of my form there are a few lines like this (one for each
TextBox):

TextBox1.DataBindings.Clear()
TextBox1.DataBindings.Add("Text", myDataTable, "column 1")

(Clearing bindings before resetting them is necessary.) This form displays
the correct details just fine when data in myDataTable has been changed
between loading the same form again. BUT:

In addition I also happend to have a DateTimePicker in my form to display
dates. The code I used here was:

DateTimePicker1.DataBindings.Clear()
DateTimePicker1.DataBindings.Add("Value", myDataTable, "column 2")

Notice that I replaced the word "Text" for the property to be bound with
"Value", because DateTimePickers don't have a Text property. That was how I
interpreted what the documentation says this parameter means.

But this was the mistake. If I bind any number of textboxes plus one
DateTimePicker in the way shown above, using "Value", the form keeps showing
the old data (i.e. the first record ever bound to the controls) over and
over, including the correct date!!

Now is this weird or what? It is easy to argue that the binding was faulty
and that this caused the malfanuction but why did it bind the datatable
correctly (including the date!) the first time round? Going by the
documentation and the fact that .NET bound the date correctly to the
DateTimePicker and that I didn't get an error message this was a tricky one
to find. Anyway, the way it works is:

TextBox1.DataBindings.Clear()
TextBox1.DataBindings.Add("Text", myDataTable, "column 1")
DateTimePicker1.DataBindings.Clear()
DateTimePicker1.DataBindings.Add("Text", myDataTable, "column 2")

Hope this may be of help to somebody else sometime :-)

Thanks again, David.

Matthias
"David Lloyd" wrote:
Matthias:

Without seeing your code, I do not if the following KB article applies to
your situation or not, however, I thought I would pass it along.

http://support.microsoft.com/default...b;en-us;812919

--
David Lloyd
MCSD .NET
http://LemingtonConsulting.com

This response is supplied "as is" without any representations or warranties.
"Matthias" <Ma******@discussions.microsoft.com> wrote in message
news:5B**********************************@microsof t.com...
Hi Team

this may be a newbie question. I have searched the discussions before
posting:

I'd like to re-use a form instance to edit record details. My data binding
(a DataTable bound to TextBoxes) works fine the first time round. I can
see,
edit and update the details from my form, then close the form.

I then like to select and refill the datatable with a different record (new
query) and open the same form again. I send the new datatable to the
(existing yet invisible) form before using ShowDialog. I have confirmed
that
the new datatable has the new record data in it, consists of only one row
and
has indeed arrived at the form. I clear the data bindings of all the
textboxes and re-set them with the new datatable. (I have also tried to
ResetBindings() for the form at this point.)

But no matter what I try in terms of Update(), Refresh(), Invalidate() the
textboxes stubbornly display the data from the original binding! I have
tried to update before and after the form has appeared. I have also tried
to
keep the original binding but clear and then re-fill the datatable with a
new
record from the database, all to no avail. I'm at my wits end.

Of course it works just fine, when I re-instantiate a new form each time I
wish to edit a new record, but I reckon that is inefficient; and also I'd
like to find out how this binding mechanism really works.

Any ideas are much appreciated.

Thanks
Matthias

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.