473,326 Members | 2,108 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Data Binding GUI refresh

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
2 4872
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: David Gray | last post by:
Greetings all, How can I use ADODB to return all tables in an access DB chosen by the user? I'm able so far to select the DB file and build up my connect string, but I would like to offer a...
0
by: serge calderara | last post by:
Dear all, I need to display in my application incoming data from an external source which is pooled every 2 seconds. Thos data actually are displaye in a listbox control, but the problem I...
3
by: Diggler | last post by:
I was working on a report that is populated with three different tables in a strongly-typed dataset. The tables are populated from custom objects rather than directly from SQL Server. I loop...
6
by: p.mc | last post by:
Hi all, I'm having major problems with a userControl which contains a datagrid. My problem concerns data binding. The Page_Load() procedure calls the DataBind procedure to bind the datagrid...
0
by: bsaran | last post by:
Hi, I have a code that sort of works. The event flow is as follows: In a user control of type "FilterControl" user selects certain values from 3 related dropdown lists. (two of them have auto...
6
by: Mikus Sleiners | last post by:
Is there any way to enable exception throws in VS 2005, that occur during binding operations? I am upset that i can't see exceptions that are thrown during binding operations. It's very hard to...
14
by: Rolf Welskes | last post by:
Hello, I have an ObjectDataSource which has as business-object a simple array of strings. No problem. I have an own (custom) control to which I give the DataSourceId and in the custom-control...
7
by: John J. Hughes II | last post by:
I have a DataGridView with a TextBoxColumn. I setting the data source to a List<stringvalue in a static class. The list is filled from a background thread. So far all is fine and it works...
0
by: John | last post by:
Hi I have a binding source to which my form controls are bound. I need to refresh the binding source such that it reads any newly entered records by other users but would still like it to remain...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.