Solved

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

Posted on 2004-03-24
3
224 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

867 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now