How to populate columns in listview VB 2008

Have a listview with 12 columns. I want to 12 separate pieces of data and put them into one or the other of each of the 12 columns.

I can do all the code EXCEPT I don't know the synax to plop a string into a row/column of a list box.

This is vb 2008 Express. I could find no such thing as "subitems" as in previous versions.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Try this:
 Dim litem As ListViewItem
        litem = ListView1.Items.Add("Main item")

         ListView1.Columns.Add("this column")
        ListView1.Columns.Add("this column")
        ListView1.Columns.Add("this column")
        ListView1.Columns.Add("this column")
        ListView1.View = View.Details
SubItems are there, but just you have to use it in another way as follows.

As you said you have set up your listview with 12 columns so :

your first line of code should be

ListView1.View = System.Windows.Forms.View.Details

This makes your listview to display all the sub items.


Form a piece of data as a subitem like this:

Dim subItem As New ListViewItem.ListViewSubItem
subItem.Text = "top" -----> your piece of data

Then your row is nothing but the ListViewItem so:

Dim wholeItem As New ListViewItem
wholeItem.Text = "1" -----> data of the first column in the row.

wholeItem.SubItems.Add("2") -----> data of second column in the same row
wholeItem.SubItems.Add("3") ------> data of third column in the same row
.... up to 12 columns or make a for loop to fetch the data from a datasource

now if you say :

wholeItem.SubItems.Insert(2, subItem)

then the data "3" will be replaced with "top".

Hope you got the idea of plopping any string at any row/column this way.
Just use Insert / Add / (IndexOf along with Text )properties



Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
chevronrodAuthor Commented:
I don't how y'all just know this stuff! But it sure helped. I've test both ideas and will now be USING both ideas. I'll be using habeehallah's the most often because of the nature of the listview I have. So I've divided the points accordingly. I hope this is better than just assigning to one and leaving the other out, since I want to use both ideas. :)

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.