|
-
Mar 4th, 2008, 06:47 PM
#1
Thread Starter
Lively Member
Adding Item to a List view
I'm trying to add 5 columns of data to a list view.
I've tried
lstPortfolio.Items(Count).SubItems(1).Text = Ticker
lstPortfolio.Items(Count).SubItems(2).Text = Convert.ToString(Shares)
lstPortfolio.Items(Count).SubItems(3).Text = Convert.ToString(Price)
lstPortfolio.Items(Count).SubItems(4).Text = Convert.ToString(Shares * Price)
but I get an error telling me that Count is out of range - because there are no rows in the list view.
I've also tried
lstPortfolio.Items.Add(Ticker & Shares & Price & Shares * Price) but all that does is put the strings together, not in separate columns.
I've come across a section that talks about adding an object class, but I'm HORRIBLE with getting classes to work
Last edited by jrowe; Mar 4th, 2008 at 07:31 PM.
-
Mar 4th, 2008, 06:53 PM
#2
Re: Adding Item to a List view
You can not access subitems that doesnt exist. If you're intending to add an new ListViewItem to the ListView, here's how you could do it:
VB.NET Code:
Dim Item As New ListViewItem(New String() {"this", "is", "a", "test"})
ListView1.Items.Add(Item)
If you're intending to add subitems to an already existing listviewitem, you'd do:
VB.NET Code:
ListView1.Items(index).SubItems.Add("this is a new subitem")
-
Mar 4th, 2008, 07:02 PM
#3
Thread Starter
Lively Member
Re: Adding Item to a List view
How would I get variables into it.
I tried
Dim Item As New ListViewItem(New String() {Ticker, Convert.ToString(Price * Shares), Convert.ToString(Shares), Convert.ToString(Price), Convert.ToString(Price * Shares)})
but that just gave me 0 straight across the board.
-
Mar 4th, 2008, 07:05 PM
#4
Re: Adding Item to a List view
Are you sure that the variables have been assigned to prior to executing that line?
-
Mar 4th, 2008, 07:31 PM
#5
Thread Starter
Lively Member
Re: Adding Item to a List view
They are now....
Thanks that worked perfectly
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|