Question ComboBox to populate texboxes!

coolzero22

Member
Joined
Aug 6, 2013
Messages
8
Programming Experience
Beginner
Hello hope anyone could help me., im just a beginner..


i have this table called Member_Loans and the corresponding fields are "ActgNumber", "LoanType", "LoanAmount" nd so on.

a person having two different loans called "appliance loan" and "bonus loan" with same "actgnumber" on same table "Member_Loans " all i want is to fill the texboxes when i select the combobox items [appliance loan] or [bonus loan] with the other fields.

Presentation1.jpg

here is the image which when i choose one of the "Loantype field" also it will populate the texboxes with the other field values...

thanks in advance!
 
You simply need to bind the same data to the ComboBox and the other controls. Making a selection in the ComboBox will then automatically update the other controls. Assuming that you have already populated a DataTable with the data from the database:
With myComboBox
    .DisplayMember = "LoanType"
    .DataSource = myDataTable
End With

myTextBox.DataBindings.Add("Text", myDataTable, "LoanAmount")
'etc.
 
You simply need to bind the same data to the ComboBox and the other controls. Making a selection in the ComboBox will then automatically update the other controls. Assuming that you have already populated a DataTable with the data from the database:
With myComboBox
    .DisplayMember = "LoanType"
    .DataSource = myDataTable
End With

myTextBox.DataBindings.Add("Text", myDataTable, "LoanAmount")
'etc.

hello jmcilhinney

tanx for the reply.... i tried this code
Try
            Dim CBO As New OleDb.OleDbDataAdapter("SELECT * FROM Member_Loans WHERE ActgNumber=" & ActgNotxt.Text, conn)
            Dim CBoDT As New DataTable
            CBO.Fill(CBoDT)
            With LoanTypeCBO
                .DisplayMember = "LoanType"
                .DataSource = CBoDT
            End With


            LoanAmountTxt.DataBindings.Add("Text", CBoDT, "LoanType")
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

but i got this error

This causes binding in the collection to bind to the same property .
parameter name binding.
 
Last edited by a moderator:
Firstly, I have edited your post to format the code and make it more readable. Please do so for us in future.

As for the issue, that means that you're trying to add more than one binding for the Text property of your TextBox, which suggests that you're executing that code more than once. If you're going to create a new DataTable every time and bind that then you need to remove the old binding first.

That's a bad idea though. Why create a new DataTable and bind it when you've already got one that's bound? Just clear the existing DataTable and repopulate it.

Also, I strongly suggest that you use parameters to insert values into SQL code every time. To learn why and how, follow the Blog link in my signature below and check out my post on Parameters In ADO.NET.

Finally, if you're not already, you should be validating the contents of ActgNotxt. If it's supposed to be a number then make sure that it's a number before using it.
 
Firstly, I have edited your post to format the code and make it more readable. Please do so for us in future.

As for the issue, that means that you're trying to add more than one binding for the Text property of your TextBox, which suggests that you're executing that code more than once. If you're going to create a new DataTable every time and bind that then you need to remove the old binding first.

That's a bad idea though. Why create a new DataTable and bind it when you've already got one that's bound? Just clear the existing DataTable and repopulate it.

Also, I strongly suggest that you use parameters to insert values into SQL code every time. To learn why and how, follow the Blog link in my signature below and check out my post on Parameters In ADO.NET.

Finally, if you're not already, you should be validating the contents of ActgNotxt. If it's supposed to be a number then make sure that it's a number before using it.


many of thanks to u... i also approach my teacher and i understand few thngs.. i able to populate the texboxes using this ...
Try
Dim sql1 As String


sql1 = "SELECT * FROM PaymentTable WHERE loantype= '" & Me.LoanTypeCBO.Text & "'"
oledbAdapter = New OleDbDataAdapter(sql1, connection)
oledbAdapter.Fill(ds)
oledbAdapter.Dispose()
connection.Close()
For i = 0 To ds.Tables(0).Rows.Count - 1
CAptalAmountTxt.Text = ds.Tables(0).Rows(i).Item(2)
InterestAmtTxt.Text = ds.Tables(0).Rows(i).Item(3)
PenaltyAmtTxt.Text = ds.Tables(0).Rows(i).Item(4)
Next
Catch ex As Exception
MsgBox(ex.ToString)
End Try

it works fine... but i still have more problems... i have to work back with normalization of my table's so i could track records easily...
hope you will still help me with my projects.. (sorry for my english)
 

Latest posts

Back
Top