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