473,812 Members | 2,907 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Beginner Question - Data Binding to a TextBox - Follow-up

Can someone help with the following problem?

Original Question:
TextBox1 is bound to a dataset and at runtime shows a value of "5"
I am trying to use that value as follows:
TextBoxA.Text = TextBox1.Text
The result that I'd expect is that TextBoxA.Text would equal 5.
The result that I get is that TextBoxA.Text equals "", or wit a
Val(function) it equals 0.

How do I get TextBoxA to equal 5?

Update:
I actually have three such values that I am trying to use and am having
the same problem on all 3.

At runtime
TextBox1.Text shows a value of 5 but has a value of ""
TextBox2.Text shows a value of 18 but has a value of ""
TextBox3.Text shows a value of 24 but has a value of ""

However:
If I change the value in any one (not all three) of the textboxes then
the values of all the textboxes are updated.
When I change the value in TextBox1 to 6 then
TextBox1.Text shows a value of 6 and has a value of 6
TextBox2.Text shows a value of 18 but has a value of 18
TextBox3.Text shows a value of 24 but has a value of 24
(I am testing this by having the values of 3 other textboxes reflect
the values of TextBox1, 2, & 3)
How do I get the values to reflect what is shown without changing one
of the original values?
Thanks again,

Jim (the beginner)

I am using Visual Basic in Visual Studio.Net

Nov 21 '05 #1
8 1592
Hi Jim,

Try:-

me.validate

Rgds,

Phil

"jimscott77 " <ji********@yah oo.com> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.com.. .
Can someone help with the following problem?

Original Question:
TextBox1 is bound to a dataset and at runtime shows a value of "5"
I am trying to use that value as follows:
TextBoxA.Text = TextBox1.Text
The result that I'd expect is that TextBoxA.Text would equal 5.
The result that I get is that TextBoxA.Text equals "", or wit a
Val(function) it equals 0.

How do I get TextBoxA to equal 5?

Update:
I actually have three such values that I am trying to use and am having
the same problem on all 3.

At runtime
TextBox1.Text shows a value of 5 but has a value of ""
TextBox2.Text shows a value of 18 but has a value of ""
TextBox3.Text shows a value of 24 but has a value of ""

However:
If I change the value in any one (not all three) of the textboxes then
the values of all the textboxes are updated.
When I change the value in TextBox1 to 6 then
TextBox1.Text shows a value of 6 and has a value of 6
TextBox2.Text shows a value of 18 but has a value of 18
TextBox3.Text shows a value of 24 but has a value of 24
(I am testing this by having the values of 3 other textboxes reflect
the values of TextBox1, 2, & 3)
How do I get the values to reflect what is shown without changing one
of the original values?
Thanks again,

Jim (the beginner)

I am using Visual Basic in Visual Studio.Net

Nov 21 '05 #2
tried me.validate on form load. No effect.
I am using a tabcontrol with multiple tabs. TextBox1-3 are on a
"Settings" tab. The target textboxes are on an "Accounts" tab.
I realize now that I do not have to edit one of TextBox1-3 for the
update to work. I do have to click on the "Settings" tab. Once I do
so all is well.
I have tried to use the focus method [tabsettings.foc us()] during form
load but focus is not changed to the "Settings" tab.

Any help would be appreciated.

Thanks, Jim

Nov 21 '05 #3
Jim,

Are you sure of what you write, this code gives for me "WhatEver" in both
textboxes.

\\\
Dim dt As New DataTable
dt.Columns.Add( "MyColumn")
dt.LoadDataRow( New Object() {"WhatEver"} , True)
TextBox1.DataBi ndings.Add("Tex t", dt, "MyColumn")
TextBox2.Text = TextBox1.Text
///

(However of course not when I change the text in textbox1, it is a string
that is placed not a reference)

I hope this helps,

Cor
Nov 21 '05 #4
The application I'm putting together uses a tabcontrol and the
textboxes I'm trying to read from are on a different tab ("Settings")
than the ones I'm trying to update ("Accounts") . TextBox1 is on
tabSettings and TextBox2 is on tabAccounts. The data is coming from an
Access data base through an OleDbConnection and the textboxes on
tabSettings are bound to particular fields in the dataset. Once
tabSettings receives focus then TextBox2.Text = TextBox1.Text works,
but not before. Note that when I click on the tabSettings the values
that I want do show in the textboxes, its just that until I click on
that tab the values are not available to the rest of the tabs on the
form.

I did find a work around though. On Form Load I used a datareader to
pull in the same data and assign it individually to the text property
of the textboxes

OleDbConnection 1.Open()
objCommand = New OleDbCommand("s elect * from tblsettings",
OleDbConnection 1)
objReader = objCommand.Exec uteReader
objReader.Read( )

txtRateDefault. Text = objReader("rate default")
txtRateMin.Text = objReader("rate min")
txtRateMax.Text = objReader("rate max")

Once the textboxes had been updated by code then the information was
available elsewhere in the form without having to first go to the tab
in question

I would like an easier solution though and to understand why this was
an issue at all. It seems it should be straight forward task.

Regardless, thanks for your help.

Jim (the beginner)

Nov 21 '05 #5
Hi Jim,

Have you tried using a datatable instead of a dataset? I tried it and it
works fine for me. I created a basic form with a tabcontrol and a button.
Each tab has a text box on it.

Dim sqlStr As String
Dim cnString As String
Dim cn As OleDb.OleDbConn ection
Dim cmd As OleDb.OleDbComm and
Dim da As OleDb.OleDbData Adapter
Dim dt As DataTable

Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
initializeConne ction()
End Sub

Public Function initializeConne ction()
Try
sqlStr = "SELECT * FROM Metrics"
cnString = "Provider=Micro soft.Jet.OLEDB. 4.0;Data
Source=c:\METRI C\MetricEngine. mdb"
cn = New OleDb.OleDbConn ection(cnString )
cmd = New OleDb.OleDbComm and(sqlStr, cn)
cn.Open()

da = New OleDb.OleDbData Adapter(cmd)
dt = New DataTable
da.Fill(dt)

cn.Close()
cmd.Dispose()
cn.Dispose()
cmd = Nothing
cn = Nothing

Catch ex As Exception
MessageBox.Show (ex.ToString)
End Try
End Function

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
fill()
End Sub

Private Sub fill()
TextBox1.Text = dt.Rows(0).Item (1)
TextBox2.Text = TextBox1.Text
MessageBox.Show (TextBox2.Text)
'the value displayed is the same value displayed in text box one
End Sub
Nov 21 '05 #6
Jim,

Can you tell next time that your textbox was not visible when you tried it.

This is a kind of normal behaviour.

Cor
Nov 21 '05 #7
I created the dataconnection, dataadapter, and the dataset using the
gui interface (drag and drop from Toolbox and Server Explorer) rather
than through code. The text boxes were then each bound to the dataset
in their respective properties windows. The only code I had to write
was:
DStblSettings1. Clear()
DAtblSettings.F ill(DStblSettin gs1, "tblSetting s")
And then I ran into my problem.

Using code to directly assign values to the textbox (same values as
were there in the first place) solved the problem. Your code does that
assignment as well and appears to be easier to work with, especially on
larger problems.

I would still like to understand why the data binding process worked
(or didn't work) the way it did or if someone else, using the same
process, generated the same problem.

Thanks for your input. I appreciate your response.

Jim

Nov 21 '05 #8
THIS WORKS!!!!

ORIGINAL CODE:
DStblSettings1. Clear()
DAtblSettings.F ill(DStblSettin *gs1, "tblSetting s")

IF I ADD THE FOLLOWING ALL IS WELL:
Me.tabControlMa in.SelectedTab = tabSettings
Me.tabControlMa in.SelectedTab = tabHome

By programatically cycling to the tabSettings tab and then back to
tabHome (where I want to start) before I do my update it seems to
initiallize the values in TextBox1, 2, & 3 and now the following works.
TextBoxA.Text = TextBox1.Text

Don't ask me why.

Thanks for everyone's help.

Jim (the beginner)

Nov 21 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1484
by: Jow Blow | last post by:
Hello All, In two different books, Simple Data Binding to a control is explained with an example of a TextBox where the data is initialized with an array. For example a class is defined as such: public class Vendor {
0
2353
by: Ann Morris | last post by:
INTRODUCTION One of the most powerful aspects of .NET and Windows Forms is data binding. Data binding is the process of associating user interface (UI) elements with a data source to generate a visual representation of data. Two types of data binding are available for Windows Forms: Simple Data Binding and Complex Data Binding. Simple data binding allows you to bind one data element to a control. In many situations you want to display...
1
2013
by: david | last post by:
MY purpose is that develop a web form with textboxes to display database contents. In design time, I follow the .Net document and click data binding property field in each TextBox, select the corresponding colunm name of database table to each textbox. In the Page_Load procedure, I type me.databind(). Compiling is OK. When I run it, I got the following error message. Did I do any thing wrong? How to do it?
3
3800
by: alan | last post by:
What I would like to do is like that, a ListView data binding with a dataset which list all records of a table( for example the table list all the information of a student student_id, name, tel....etc). Besides, there are some textbox will display the student information when I click on one of the record on the ListView so that I can update the records in the textbox. I can do the data binding for the ListView and the dataset, butI don't...
19
2350
by: Simon Verona | last post by:
I'm not sure if I'm going down the correct route... I have a class which exposes a number of properties of an object (in this case the object represents a customer). Can I then use this object to databind to text boxes etc? I can't use a dataset as the object has loads of derived logic, for example updating one property may actually update several database fields for example.
8
3719
by: jimscott77 | last post by:
Can someone help with the following problem TextBox1 is bound to a dataset and shows a value of "5" I am trying to use that value as follows Variable1 = Val(TextBox1.Text) The result that I'd expect is that Variable1 would equal 5. The result that I get is that Variable1 equals 0
0
1495
by: AM | last post by:
The following block of code defines a FormView control "FormView1" with an EditItemTemplate which has a Label and a TextBox control within it. While the Label "RequestIDLabel1" has one-way data-binding to the underlying column "RequestID", the TextBox "RequestDateTextBox" has two-way data-binding to the underlying column. If I were to generate the EditItemTemplate dynamically at runtime, and add the Label and TextBox controls at...
0
1856
by: EricLondaits | last post by:
Hi, I have an ASP.NET page with a ListBox that is data bound to a table with a single field (it holds a list of valid IDs). The page also has a textBox into which you can add new valid IDs, one per line (this is in order to make the process of adding new IDs easy, since it's only done at time of configuration). I have no problem with retrieving the contents of the textBox, splitting it into a string array, validating the individual...
5
1608
by: raajakumars | last post by:
urgent!!!!!!! kindly please anyone help me....... actualy i am newbe to vb.net i need data to be inserted in to my table like this... sitenm cdate wrknm nowrk totwg tamiz palace 12/1/2007 Electrician 34 5100 tamiz palace 12/1/2007 Mason 5 900 instead my following code produces result like this..
1
1968
by: sampalmer21 | last post by:
Hi, I'm creating a database application using c# and ado.net with winforms controls. In sql there is a data type called money which stores values in the format xx.xxxx, this is not in the typical currency fashion of $xx.xx, therefore I use the following sql command and ADO.NET's DataReader class to convert the sql money format to a currency format before displaying it on a textbox control: SELECT Qty, '$' + CONVERT(varchar(12),...
0
9734
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9607
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10664
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10404
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9219
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7677
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5568
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5704
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3029
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.