Hello guys im in need of a help. I have a checkbox on a Listview1 and i also have listview2, textbox and 2 buttons. On listview1, i have a list of items and its subitems. Then im going to put a check on the one of the listview item then once i click the button1 the value of the sub item of that item will be put into textbox. Then on button2 i have the select statement where it's WHERE is textbox.text and it will display the data of that item from database to listview2. Once i run my program, check the item from listview1 then click button1, its working fine it puts the value of that listview1 to textbox1 but when i click button2 it dont work. But if i am the one putting value on textbox.text it is working, so i think the problem is when it transfer the value from listview to textbox3. I dont know what to do. Sorry if my explanation is not that understandable enough, thats my best in explaining my problem :s Thanks in advance to whoever will help me solve my problem.. i need this to finish my thesis. Thank you.

This is my code on my button1. This sends the value of subitem into textbox.text.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles printbtn.Click

Dim item As ListViewItem

        Dim checkedItems As ListView.CheckedListViewItemCollection = _
            ListView1.CheckedItems

        For Each item In checkedItems
            TextBox.Text = item.SubItems(7).Text
         Next
End Sub

Then my function on button2.

Public Sub showtest()


        connstring = "Data Source=.\SQLEXPRESS;AttachDbFilename=""C:\Users\Pabzz\Desktop\CSRP 10.20.12\Main\Database1.mdf"";Integrated Security=True;Connect Timeout=30;User Instance=True"
        conn.ConnectionString = connstring

        Dim dt As New DataTable
        Dim ds As New DataSet

        sql = "SELECT * FROM Books_Table WHERE rfidtag='" & TextBox3.Text & "'"

        Dim da As New SqlDataAdapter(sql, conn)

        conn.Open()
        da.Fill(dt)
        conn.Close()

        Dim dRow As DataRow


        For Each dRow In dt.Rows

            ListView2.Items.Add(dRow.Item(0).ToString)
            ListView2.Items(ListView2.Items.Count - 1).SubItems.Add(dRow.Item(1).ToString)
            ListView2.Items(ListView2.Items.Count - 1).SubItems.Add(dRow.Item(2).ToString)
            ListView2.Items(ListView2.Items.Count - 1).SubItems.Add(dRow.Item(3).ToString)
            ListView2.Items(ListView2.Items.Count - 1).SubItems.Add(dRow.Item(4).ToString)
            ListView2.Items(ListView2.Items.Count - 1).SubItems.Add(dRow.Item(5).ToString)
            ListView2.Items(ListView2.Items.Count - 1).SubItems.Add(dRow.Item(6).ToString)
            ListView2.Items(ListView2.Items.Count - 1).SubItems.Add(dRow.Item(7).ToString)
            ListView2.Items(ListView2.Items.Count - 1).SubItems.Add(dRow.Item(8).ToString)

        Next

    End Sub

Recommended Answers

All 5 Replies

Change your DataSource string - you need only the opening and closing quotes.
From:
connstring = "Data Source=.\SQLEXPRESS;AttachDbFilename=""C:\Users\Pabzz\Desktop\CSRP 10.20.12\Main\Database1.mdf"";Integrated Security=True;Connect Timeout=30;User Instance=True"

To:
connstring = "Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Pabzz\Desktop\CSRP 10.20.12\Main\Database1.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"

Try that and see if it helps.

It looks like you're also not even using the ds variable...

A cleaner add would be

For Each dRow In dt.Rows

    Dim item As New ListViewItem(dRow.Item(0).ToString)

    For i As Integer = 1 To 8
        item.SubItems.Add(dRow.Item(i).ToString)
    Next

    ListView2.Items.Add(item)

Next

If these suggestions solved your issue, please mark the thread as "solved"
Thanks

It looks to me that your putting the info into textbox but your reading the info from textbox3.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.