• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 897
  • Last Modified:

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.

2 Solutions
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


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. :)

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now