Groups | Blog | Home
all groups > vb.net controls > april 2005 >

vb.net controls : Listview...


Guy Cohen
4/29/2005 12:00:00 AM
Hi all...
Lets say I want to add 100 items (e.g. Row1, Row2....Row100) to a listview
and for each item I want to add two subitems (total columns=3).

Do I have to declare a new listitem variable for each listitem ?....
TIA
Guy

Crouchie1998
4/29/2005 12:00:00 AM
1) Start a new Windows application

Add a ListView control

2) Add these declarations:

Dim intRow As Integer
Dim lvi As ListViewItem

3) Double-click the form & paste this in the Form_Load event():

With ListView1
.View = View.Details
.Columns.Add("Column 1", 100, HorizontalAlignment.Left)
.Columns.Add("Column 2", 100, HorizontalAlignment.Left)
.Columns.Add("Column 3", 100, HorizontalAlignment.Left)
End With

For intRow = 1 To 100
lvi = New ListViewItem(intRow)
lvi.SubItems.Add(intRow + 1)
lvi.SubItems.Add(intRow + 2)
ListView1.Items.Add(lvi)
Next

4) Run the sample

Example output:

1 2 3
2 3 4
3 4 5
4 5 6
....
100 101 102

I hope this helps

Crouchie1998
BA (HONS) MCP MCSE

AddThis Social Bookmark Button