Listbox items on Form1 show on Form2 Textboxes

Discussion in 'Programming General' started by LymX, Aug 17, 2012.

Listbox items on Form1 show on Form2 Textboxes
  1. Unread #1 - Aug 17, 2012 at 11:54 AM
  2. LymX
    Joined:
    Mar 19, 2009
    Posts:
    16
    Referrals:
    0
    Sythe Gold:
    10

    LymX Newcomer

    Listbox items on Form1 show on Form2 Textboxes

    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
     
  3. Unread #2 - Aug 17, 2012 at 2:17 PM
  4. matt_sells
    Joined:
    Nov 28, 2011
    Posts:
    78
    Referrals:
    0
    Sythe Gold:
    0

    matt_sells Member

    Listbox items on Form1 show on Form2 Textboxes

    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.
     
  5. Unread #3 - Aug 17, 2012 at 8:59 PM
  6. LymX
    Joined:
    Mar 19, 2009
    Posts:
    16
    Referrals:
    0
    Sythe Gold:
    10

    LymX Newcomer

    Listbox items on Form1 show on Form2 Textboxes

    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???
     
< Raps help n Mac | Visual Basic 2010 question. >

Users viewing this thread
1 guest


 
 
Adblock breaks this site