473,385 Members | 1,782 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,385 software developers and data experts.

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 1570
Hi Jim,

Try:-

me.validate

Rgds,

Phil

"jimscott77" <ji********@yahoo.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.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.focus()] 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.DataBindings.Add("Text", 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

OleDbConnection1.Open()
objCommand = New OleDbCommand("select * from tblsettings",
OleDbConnection1)
objReader = objCommand.ExecuteReader
objReader.Read()

txtRateDefault.Text = objReader("ratedefault")
txtRateMin.Text = objReader("ratemin")
txtRateMax.Text = objReader("ratemax")

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.OleDbConnection
Dim cmd As OleDb.OleDbCommand
Dim da As OleDb.OleDbDataAdapter
Dim dt As DataTable

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
initializeConnection()
End Sub

Public Function initializeConnection()
Try
sqlStr = "SELECT * FROM Metrics"
cnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=c:\METRIC\MetricEngine.mdb"
cn = New OleDb.OleDbConnection(cnString)
cmd = New OleDb.OleDbCommand(sqlStr, cn)
cn.Open()

da = New OleDb.OleDbDataAdapter(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(ByVal sender As System.Object, ByVal e As
System.EventArgs) 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.Fill(DStblSettings1, "tblSettings")
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.Fill(DStblSettin*gs1, "tblSettings")

IF I ADD THE FOLLOWING ALL IS WELL:
Me.tabControlMain.SelectedTab = tabSettings
Me.tabControlMain.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
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...
0
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...
1
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...
3
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,...
19
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...
8
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...
0
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...
0
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...
5
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...
1
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
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...

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.