Question ListView Loading SubItem error

hisheeraz

Member
Joined
Oct 5, 2008
Messages
11
Programming Experience
1-3
sorry my fellow friends

i am able to successfully ad to the first column of listview but i am having error adding submenu items i am posting my code for your understanding, i have 5 column in the listview

VB.NET:
        Dim iForLoop As Integer
        Dim ds As DataSet
        Dim da As System.Data.OleDb.OleDbDataAdapter

        sql = "SELECT * FROM tblRoster"
        da = New OleDb.OleDbDataAdapter(sql, con)
        ds = New DataSet
        da.Fill(ds, "tblRoster")
        sqlR_Count = ds.Tables(0).Rows.Count

        For iForLoop = 0 To sqlR_Count - 1
            Dim New_Item = New ListViewItem
            New_Item.Text = (ds.Tables("tblRoster").Rows(iForLoop)("eDate"))
       'im getting error at the line below
            New_Item.SubItems(1).Text = (ds.Tables("tblRoster").Rows(iForLoop)("CarNumber"))
            New_Item.SubItems(2).Text = (ds.Tables("tblRoster").Rows(iForLoop)("DriverName"))
            New_Item.SubItems(3).Text = (ds.Tables("tblRoster").Rows(iForLoop)("ShiftType"))
            New_Item.SubItems(4).Text = (ds.Tables("tblRoster").Rows(iForLoop)("PaymentStatus"))

            lvViewRoster.Items.Add(New_Item)
        Next iForLoop
here is the error i am getting at the first subitem code
VB.NET:
InvalidArgument=Value of '1' is not valid for 'index'. Parameter name: index

any help will be appreciated
thanks
shiraz
 
You have no subitem at index 1. Use the Add method to add a subitem. (.SubItems.Add)
 
Back
Top