• Log in or sign up for an account here: https://www.sythe.org/login

Listbox items on Form1 show on Form2 Textboxes

LymX

Newcomer
Joined
Mar 19, 2009
Sythe Gold
10
Messages
16
How do you show on textboxes in Form2 the items on listbox in form1. Like i have a "123" data on listbox1 (Form1) then i need to check that if it matches in my database, and if it does, on form2 textboxes, it will display additional information of that from database.

Code:
Form1
    Private Sub listBox3_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles listBox3.SelectedIndexChanged
        Form2.TextBox6.Text = listBox3.GetItemText(listBox3.SelectedItem)

        If listBox3.GetItemText(listBox3.SelectedItem) = "09 00 EE 00 1F 4F 30 00 75 E0 " Then
            MsgBox("SUCCESS")
            'Me.Hide()
            Form2.Show()
        Else
            MsgBox("FAIL")
        End If
    End Sub

Code:
Form2
        connstring = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Csrp2_DB.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
        conn.ConnectionString = connstring








        If TextBox6.Text = "09 00 EE 00 1F 4F 30 00 75 E0 " Then
            sql = "SELECT * from Csrp2_table1 Where Title='" & UCase(TextBox1.Text) & "'" + _
                ",Author='" & UCase(TextBox2.Text) & "'" + _
                ",Price='" & UCase(TextBox3.Text) & "'" + _
                ",Stock='" & UCase(TextBox4.Text) & "')"
            Else
            MsgBox("FAIL")
        End If
 
using multiple forms for jobs like that will soon make your project super cluttered, however you do it by using public shared.
in your second form
public shared textbox2text as textbox

then for simplicity put textbox2text = textbox2 in form2's load and you'll be able 2 use textbox2text in form1.

I might be wrong, but just create a global string rather than using textboxes from different forms.
 
Hey thanks for trying to help, i appreciate it but i got another problem.Can you tell me whats wrong on my code. Im trying to get the data of Title, Author, Price, Stock from DB and output it on my textboxes.

Code:
    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


        connstring = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Csrp2_DB.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
        conn.ConnectionString = connstring



        If TextBox6.Text = form1.TextBox6.Text Then
            sql = "SELECT from Csrp2_table1 (Title, Author, Price, Stock) Values ('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "')"

            MsgBox("BZZ")
        Else
            MsgBox("FAILs")
        End If


        Dim da As New SqlDataAdapter(sql, conn)

        conn.Open()
        da.Fill(ds)
        conn.Close()
    End Sub


Or do you guys think im missing this code
Code:
" WHERE RFID = '" textbox6.text " ' "

but where should i put it???
 
Runescape Gamblingrunescape gambling
Back
Top