Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleEasily make ListView rows programmatically in VB .NET
KeywordsListView, rows, VB.NET
CategoriesVB.NET, Controls
 
Subroutine ListViewMakeRow takes as parameters a ListView control, an item's title, and a ParamArray giving the text for the item's sub-items. It makes the new item and then loops through the ParamArray making sub-items for each entry.
 
' Make a ListView row.
Private Sub ListViewMakeRow(ByVal lvw As ListView, ByVal _
    item_title As String, ByVal ParamArray subitem_titles() _
    As String)
    ' Make the item.
    Dim new_item As ListViewItem = lvw.Items.Add(item_title)

    ' Make the sub-items.
    For i As Integer = subitem_titles.GetLowerBound(0) To _
        subitem_titles.GetUpperBound(0)
        new_item.SubItems.Add(subitem_titles(i))
    Next i
End Sub
 
The program would use this subroutine as in:
 
ListViewMakeRow(lvwBooks, _
    "Ready-to-Run Visual Basic Algorithms", _
    "http://www.vb-helper.com/vba.htm", _
    "0-471-24268-3", "http://www.vb-helper.com/vba.jpg", _
    "395", "1998")
ListViewMakeRow(lvwBooks, _
    "Visual Basic Graphics Programming", _
    "http://www.vb-helper.com/vbgp.htm", _
    "0-472-35599-2", _
    "http://www.vb-helper.com/vbgp.jpg", _
    "712", "2000")
...
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated