• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 285
  • Last Modified:

Binding Textboxes for lookup

Is there a way of using similar code or just another way to achieve the same outcome as;

CmbLocation.DataSource = DataSet11.Tables("Locations")
        CmbLocation.DisplayMember = "LocationName"
        CmbLocation.ValueMember = "LocationID"
        CmbLocation.DataBindings.Add("selectedvalue", dv, "LocationID")

Using textboxes instead of comboboxes?
  • 4
  • 2
1 Solution
Yes you can use DataBindings with TextBoxes as well
But you see textBoxes can display only one value so there's no point unless you provide a mechanism for Navigation we usually use CurrencyManger for it

I'll just post a sample for you

    Dim DTOutage As DataTable = New DataTable("Emp")
    Dim CMgr As CurrencyManager

    Private Sub FrmDetails_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim Cn As OleDbConnection = New OleDbConnection(ConnStr)
            Dim DA As OleDbDataAdapter = New OleDbDataAdapter("Select * From Emp", Cn)
           'Load the dataTable and Bind the Currency manager to it
            CMgr = BindingContext(Emp)
         'Now Here's How you bind various Controls I have tried to use all famliar controls  
         CmbEmpID.DataBindings.Add("Text", Emp, "EmpID")
         TxtName.DataBindings.Add("Text", Emp, "EmpName")
         DTPJoiningDate.DataBindings.Add("Text", Emp, "JoiningDate")

    End Sub

        Private Sub MoveFirst()
        CMgr.Position = 0
     End Sub

    Private Sub MovePrevious()
        CMgr.Position = CMgr.Position - 1
     End Sub

    Private Sub MoveNext()
        CMgr.Position = CMgr.Position + 1
    End Sub

    Private Sub MoveLast()
        CMgr.Position = CMgr.Count - 1
    End Sub
When you call any of the Move functions you'd see the data changing in the TextBox
Sorry I made a mistake
The first line would be

Dim Emp As DataTable = New DataTable("Emp")
rather than
Dim DTOutage As DataTable = New DataTable("Emp")

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.

matt_swinburneAuthor Commented:
TxtName.DataBindings.Add("Text", Emp, "EmpName") this line will just bind it to one location wont it.  I need it to look in the 1st location get the ID number then goto another table look the number up and use it to add the description stored in the other table.
OK so it's more than one table
I assume it's like all the IDs are there in a ComboBox
User selects an ID then the textBoxes should show values corresponding to that ID only is it ??
for eg if I select a DeptID only the Employees of that dept will be shown is it???

matt_swinburneAuthor Commented:
No sorry maybe im not being clear, I have two tables.  The main table called client and a secondary one called destinations for example.  One field in the client database might be destination ID.  The data might be 1, 2, 3,4 or 5.  I need the textboxes to look at destination ID then goto the table destinations and look at a field destination ID then look to the field destination name and return the name and not the ID no.  
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now