Results 1 to 3 of 3

Thread: ListView Loading SubItem error

  1. #1
    hisheeraz is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.5 (VS 2008)
    Join Date
    Oct 2008
    Posts
    11
    Reputation
    59

    Question ListView Loading SubItem error

    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

    Code:
            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
    Code:
    InvalidArgument=Value of '1' is not valid for 'index'. Parameter name: index
    any help will be appreciated
    thanks
    shiraz

  2. #2
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    14,204
    Reputation
    2369
    You have no subitem at index 1. Use the Add method to add a subitem. (.SubItems.Add)

  3. #3
    hisheeraz is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.5 (VS 2008)
    Join Date
    Oct 2008
    Posts
    11
    Reputation
    59
    your are a genious,
    thanks for saving me from trouble
    cheers
    shiraz

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Harvest time tracking