ListView columns in detail mode

R

Rob Richardson

Greetings!

I am attempting to display data in tabular form using a ListView control in
detail mode. This is for a program I originally wrote in VB6. In VB6, I
would add an item to the ListView, and the item would automatically have the
correct number of subitems, which I could access using array syntax. That
doesn't seem to be the case in VB .Net. I tried creating a two-column
listview. I added an item, and then tried to set the first subitem's text.
I expected that the text I supplied for the item would appear in the first
column and the text for subitem 0 would appear in the second column. That's
what would have happened in VB6. It didn't. The text for the item appeared
in the first column, but text for subitem 0 overwrote the first column, and
the second column remained empty. If I used SubItems.Add, I would get what
I wanted.

But what if I don't want to fill in all columns? In VB6, I automatically
had the correct number of subitems, and I could fill in columns 1, 2, 5, 6
and 7 and leave the rest blank. In .Net, I have to add a subitem for all of
the columns, even if I'm not going to be using them for that particular row.
The only way I can think of to do that is to use build an array of empty
strings of the correct size and use SubItems.AddRange or Item's constructor
that accepts a string array to pre-build my subitems. Why doesn't the
ListView control automatically give me the correct number of subitems for an
item, since it knows how many columns I have?

Thanks very much!

Rob
 
C

Cor

Hi Rob,

This is a VB.net newsgroup, I read a lot in your message what you should do
in VB6.

But what is what you want to archieve with the listview in VB.net, that is
for most of us much easier to answer.

I do not know one control which is exactly the same in VB6 as in VB.net even
not the label.

Cor
 
R

Rob Richardson

Cor,

Thank you for your reply. Yes, I know this group is for VB .Net. So, the
question remains: When I create a ListView control in detail mode with a
certain number of columns, does it automatically give me the correct number
of subitems? It doesn't seem to, and I don't understand why not, since VB
..Net knows how many columns I created in it. If not, what is the preferred
way to create the subitems I will need?

Thank you very much.

Rob
 
C

Cor

Hi Rob,

First of all, I think there is no preferred way in vb.Net.

Maybe there are some unpreferred.

A lot of things in VB.net (or better in the framework) are made of parts,

We see it everytime back in a lot of on first sigth totally different
things.

The listview can holds references to a listviewitems a seperate class and a
the listviewitem can holds by instance an image and listviewsubitems.

When you are creating items, rembember that you have everytime to create an
item or a subitem and than you can add, insert, remove and removeat that
item to/from a higher level.

Another point of watch for is that the listview has 4 viewstates the same as
explorer.

Here is a link on msdn, that gives the members of the listviewsubitem.

http://msdn.microsoft.com/library/d...itemlistviewsubitemcollectionmemberstopic.asp


I hope this helps a little bit.

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top