Advertisement

05.02.2008 at 08:29PM PDT, ID: 23373419
[x]
Attachment Details

Listview

Asked by kethy in Microsoft Visual Basic.Net

Tags: Microsoft, Visual studio, vb.net, Vb.net

I created few textfields and a listview to display the data from the database. When i hover listview, i want the data associated to display on the respective textfield.

My code can work perfectly but only customer ID field can be shown in list view and show the data in respective textfield when i hover. Other record are not shown in the listview and it giving me this error when i execute the code.  
InvalidArgument=Value of '1' is not valid for 'index'. Parameter name: indexStart Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
Public Sub fill(ByVal str, ByVal tstr)
        Dim i As Integer
        con.ConnectionString = connString
        con.Open()
 
        ListView1.Items.Clear()
        ListView1.Sorting = SortOrder.Ascending
 
        com1 = New OleDbCommand(str, con)
        datareader = com1.ExecuteReader()
 
        While datareader.Read()
            lvitem = New ListViewItem(datareader(0).ToString())
 
            For i = 1 To i <= datareader.FieldCount - 1
 
                lvitem.SubItems.Add(datareader(i).ToString())
 
            Next i
            ListView1.Items.Add(lvitem)
        End While
 
        con.Close()
 
    End Sub
 
    Public Sub filltext(ByVal str, ByVal tstr)
 
        con.ConnectionString = connString
        con.Open()
 
        com1 = New OleDbCommand(str, con)
 
 
        datareader = com1.ExecuteReader()
        If datareader.Read() Then
 
            TextBox3.Text = datareader("Customer_ID").ToString()
            TextBox1.Text = datareader("Customer_Name").ToString()
            TextBox2.Text = datareader("Cash").ToString()
 
            TextBox4.Text = datareader("Cheque").ToString()
            TextBox5.Text = datareader("Outstanding").ToString()
            TextBox6.Text = datareader("TodayDate").ToString()
 
        End If
        datareader.Close()
        con.Close()
 
 
    End Sub
 
 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 
        str = "Select * from customer order by Customer_ID"
        tstr = "customer"
 
        fill(str, tstr)
        filltext(str, tstr)
 
    End Sub
 
 
    Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged
        TextBox1.Text = (ListView1.Items(ListView1.FocusedItem.Index).SubItems(1).Text)
        TextBox1.Text = (ListView1.Items(ListView1.FocusedItem.Index).SubItems(1).Text)
        TextBox2.Text = (ListView1.Items(ListView1.FocusedItem.Index).SubItems(2).Text)
        TextBox4.Text = (ListView1.Items(ListView1.FocusedItem.Index).SubItems(3).Text)
        TextBox5.Text = (ListView1.Items(ListView1.FocusedItem.Index).SubItems(4).Text)
        TextBox6.Text = (ListView1.Items(ListView1.FocusedItem.Index).SubItems(5).Text)
    End Sub
[+][-]05.02.2008 at 09:25PM PDT, ID: 21491309

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Microsoft Visual Basic.Net
Tags: Microsoft, Visual studio, vb.net, Vb.net
Sign Up Now!
Solution Provided By: jaime_olivares
Participating Experts: 1
Solution Grade: A
 
 
[+][-]05.02.2008 at 09:39PM PDT, ID: 21491332

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628