Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 274
  • 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?
0
matt_swinburne
Asked:
matt_swinburne
  • 4
  • 2
1 Solution
 
arif_eqbalCommented:
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
0
 
arif_eqbalCommented:

    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)
            Cn.Open()
            Dim DA As OleDbDataAdapter = New OleDbDataAdapter("Select * From Emp", Cn)
           
           'Load the dataTable and Bind the Currency manager to it
            DA.Fill(Emp)
            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")

            DA.Dispose()
    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
0
 
arif_eqbalCommented:
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")


0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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.
0
 
arif_eqbalCommented:
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???

0
 
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.  
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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