Solved

Binding One DB Field, To Multiple Controls (50 Points)

Posted on 2004-03-24
3
244 Views
Last Modified: 2010-04-17
In Visual Basic.Net: I have an Access DB, and i want to Bind a Phone Field Stored As XXX XXX XXXX no spaces. I want to bind it to 3 sperate text boxes without using an invisable intermediate textbox. is this possible? a small code snippet would also be appreciated if possible. Thanks
0
Comment
Question by:RHopkinson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 3

Expert Comment

by:pamboo
ID: 10674958
What is the type of  Phone Field ?  Number or Text
0
 
LVL 3

Accepted Solution

by:
pamboo earned 50 total points
ID: 10675228
I suggest it might be a Text field since number type cannt hold large values (10 digit values) .

Considering u have declared the phone field as text , just try the below .

U bind all the 3 textboxex to the same field

Say dt is ur DataTable

Me.TextBox1.DataBindings.add("Text",dt,"Phone_Field")
Me.TextBox2.DataBindings.add("Text",dt,"Phone_Field")
Me.TextBox3.DataBindings.add("Text",dt,"Phone_Field")

In the TextChanged event of above 3 textbox do the below

'First text box should contain the digits 8 to 10
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

 If  Me.TextBox1.Text <> vbNullString Then

  If Me.TextBox1.Text.Length > 7 then
    Me.TextBox1.Text = Mid(Me.TextBox1.Text,1,Me.TextBox1.Text.Length-7)
  else
    Me.TextBox1.Text = VbNullString ' Or  Me.TextBox1.Text = "000"
  End If

 End If

End Sub

Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged

 If  Me.TextBox2.Text <> vbNullString Then

  If TextBox2.Text.Length <= 4 then
     Me.TextBox2.Text = VbNullString ' Or  Me.TextBox1.Text = "000"
  If TextBox2.Text.Length <= 7 and TextBox2.Text.Length >= 5 then
     Me.TextBox2.Text = Mid(Me.TextBox2.Text,1,Me.TextBox1.Text.Length-4)
  Else  If TextBox2.Text.Length > 7
     Me.TextBox2.Text = Mid(Me.TextBox2.Text,Me.TextBox1.Text.Length-6,3)
 End If

End Sub

Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged
 If  Me.TextBox3.Text <> vbNullString Then
  If TextBox3.Text.Length > 4 then
     Me.TextBox3.Text = Mid(Me.TextBox3.Text,Me.TextBox3.Text.Length-3)
 End If
End Sub

- Rajan
0
 

Author Comment

by:RHopkinson
ID: 10680217
Thanks, Works Great!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
numbers ascending pyramid 101 264
Delphi: barcode reading on android platform 1 99
Help Required 2 56
Starting to use Git with Visual  Studio Online 1 69
A short article about a problem I had getting the GPS LocationListener working.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question