List view subitems

dashley

Well-known member
Joined
May 27, 2005
Messages
59
Location
Tennessee
Programming Experience
10+
I'm having a problem getting a listview to display subitems.
I've never had a problem with it until I used the .NET CF for a ppc.

I've tried this code but it tells me I need an index ("additional information:index) on the line marked ** below. I add an index of zero to start with but no luck.
VB.NET:
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] Contact1 [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] ListViewItem[/SIZE]
 
[SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].ListView1.Items.Add(Contact1)[/SIZE]
 
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] Contact2 [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] ListViewItem[/SIZE]
 
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] Contact3 [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] ListViewItem.ListViewSubItem[/SIZE]
 
[SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].ListView1.Items.Add(Contact2)[/SIZE]
 
[SIZE=2]Contact1.Text = "HELLO"[/SIZE]
 
[SIZE=2]Contact2.Text = "HELLO 2"[/SIZE]
 
[SIZE=2]Contact3.Text = "HELLO 3"[/SIZE]
 
[SIZE=2]Contact1.SubItems.Add(Contact3) ***[/SIZE]
 
[SIZE=2]ListView1.View = View.Details[/SIZE]
 
[SIZE=2]ListView1.Columns.Add("Col 1 ", 80, HorizontalAlignment.Center)[/SIZE]
 
[SIZE=2]ListView1.Columns.Add("Col 2 ", 80, HorizontalAlignment.Center)[/SIZE]
 
Last edited by a moderator:
Resolved

Well after hours of messing with different things I finally got it. Here's a sample
Makes 2 colums with 5 items in each column
VB.NET:
dim i as integer
 
 
for I = 1 to 5
 
Dim lvi As ListViewItem = New ListViewItem(i)
lvi.SubItems.Add(i)
 
ListView1.Items.Add(lvi)
 
next
 
Me.ListView1.Columns.Add("Categories", 160, HorizontalAlignment.Left)
 
Me.ListView1.Columns.Add("Unit", 40, HorizontalAlignment.Left)
 
ListView1.View = View.Details
 
Last edited by a moderator:
Back
Top