473,372 Members | 1,074 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,372 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 4874
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.