ListView Control

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

When using the Properties table at design time, I add two items to the column
collection. I then add two items to the items collection which shows up
under the first column. I then add a subitem to each of the Items in the
Items collection. These should show up in the second column. However, what
actually happens is the items text is replaced with the subitems text and I
only get the subitems names in the first column. I checked the resultant
coding that the designer created and it totally ignored the sub items and
used the subitem names for the items.

Is this a bug? When I do it in code at runtime, it works ok.
 
Dennis,

Why should it be a bug, are you sure you did set all the needed
columnheaders and the style to details?

Cor

"Dennis"
 
Yes, I set the view style to Details..otherwise I couldn't see the column
headers. It's a bug to me so far since I believe I'm doing everything
correctly. I can create the items and subitems in code at runtime and they
show up ok like

Col1 Col2 Col3 Col4
item1 subitem1.1 subitem1.2 subitem 1.3
item2 subitem2.1 subitem2.2 subitem 2.3

But when I try to do it in design time, I get

Col1 Col2 Col3 Col4
subitem1.3
subitem2.3

It seems as if the items are replaced with the last subitem I entered in the
properties table.
 
Hi Dennise,

It's probably better practice to add your items to the listview at
run-time anyway, only because the forms designer can be a bit flaky at
times. I've lots programming work by relying on adding data at design time,
I'm sure I'm not the only one :-\

Dim mylistviewitem as new ListViewItem("The should appear in the first
column")
mylistviewitem .SubItems.Add("This should appear in the second column")
mylistviewitem .SubItems.Add("This should appear in the third column")

Call mylistview.Items.Add(mylistviewitem)

^ Something like that.

Nick.
 
Dennis,

This is a part of a sample I have sand today, see if you do it the same
(The code in the designer hidden part should be something like this)

I hope this helps?

Cor

\\\Sample needs only a form the rest is made dynamicly
Friend WithEvents lv As New ListView
Friend WithEvents ch1 As New ColumnHeader
Friend WithEvents ch2 As New ColumnHeader
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim lvi1 As ListViewItem = New ListViewItem(New String() {"1", "One"}, -1)
Dim lvi2 As ListViewItem = New ListViewItem(New String() {"2", "Two"}, -1)
Dim lvi3 As ListViewItem = New ListViewItem(New String() {"3",
"Three"}, -1)
Dim lvi4 As ListViewItem = New ListViewItem(New String() {"4",
"Four"}, -1)
Dim lvi5 As ListViewItem = New ListViewItem(New String() {"5",
"Five"}, -1)
lv.Columns.AddRange(New ColumnHeader() {ch1, ch2})
lv.Items.AddRange(New ListViewItem() {lvi1, lvi2, lvi3, lvi4, lvi5})
lv.Location = New System.Drawing.Point(10, 10)
lv.Size = New System.Drawing.Size(150, 150)
lv.TabIndex = 0
lv.View = View.Details
Controls.Add(lv)
End Sub
///
 
What I get in the Designer code is the following where "Item1" and "Item2"
are replaced with the text I enter in the designer subitems collection:

Dim ListViewItem1 As System.Windows.Forms.ListViewItem =
NewSystem.Windows.Forms.ListViewItem("Item1")
Dim ListViewItem2 As System.Windows.Forms.ListViewItem =
NewSystem.Windows.Forms.ListViewItem("Item2")
Me.ListView1 = New System.Windows.Forms.ListView
Me.ColumnHeader1 = New System.Windows.Forms.ColumnHeader
Me.ColumnHeader2 = New System.Windows.Forms.ColumnHeader
Me.SuspendLayout()
'
'ListView1
'
Me.ListView1.Columns.AddRange(New System.Windows.Forms.ColumnHeader()
{Me.ColumnHeader1, Me.ColumnHeader2})
Me.ListView1.Items.AddRange(New System.Windows.Forms.ListViewItem()
{ListViewItem1, ListViewItem2})
 
Dennis,

Probably you are not filling the subitem collection which is in the
itemproperty box

I hope this helps?

Cor
 
Not sure what you mean by "ItemProperty Box". In the list of properties,
under Items (collection) you can enter a list of items. For each item, there
is a text, color, etc. and at the top to the right is a Subitems (collection)
which you should be able to enter subitems for the selected item. However,
whenever I enter a subitem, it replaces the item text.
 
Did you place in the subitems as well the text?

Than it should become something as this I showed you before

Dim listview1 As ListViewItem = New ListViewItem(New String() {"1",
"One"}, -1)

Cor
 
Yes, I did enter text in the subitems but it only replaced the text in the
main item.
 
Dennis Strange,

To Item1 I added a subitem and to Item2 not using the designer.

Dim ListViewItem1 As System.Windows.Forms.ListViewItem = New
System.Windows.Forms.ListViewItem(New String() {"Item1", "Subitem"}, -1)
Dim ListViewItem2 As System.Windows.Forms.ListViewItem = New
System.Windows.Forms.ListViewItem("Item2")

Strange that you get with adding subitems the situation when you add no
subitems, is there a dwarf in your computer maybe?

:-)

Cor
 
Not sure what dwarf means but if you mean a little devil screwing me around
in my computer, then it appears so. Hey, thanks for trying to help. I'll
just live with it until I get vs.net 2005 and when I load it, maybe it will
work. Thanks again.
 
Hi Dennis,

If you rely of the forms designer to feed your application it's data
then you are surely to encounter problems. The designer is just a niceity
really, and it will probably always have errors :-(

Nick.
 
Nick,

Can you try this with 2002
Drag a listview to your empty form
Open properties from that
Set view to details
Open the collection properties subscreen
Add in that two items fill in that the "texts" items by instance "one" and
in the other "two"
Open in both of the items the subscreen collections what you see in the top
of the properties of the itemscreen on by one
Add a subitem and give that as text whatever by instance Nick
Do that the same for the other item with the text Cor
Go back to the listview properties and add in the header collection two
headers nothing more
Run

Probably testing this cost a lot less time than writing above

It should show
header header
one Nick
two Cor

Cor
 
Hi there,

Right, in order to see anything I needed to add at least 1 column, I
added 2 columns to show the *subitem* bit got a strange result.

The designer seems to have overwritten the item with the first sub item.
Which *technically* is correct, because subitem(0) in a listview item is the
*first* column.

So order to get the same results as yourself I needed to add 2 subitems
to each listview item (0) and (1) and voila. The first item in *every* sub
item is the parent item.

Nick.
 
Nick,

Thanks what you said is I thought as well something Dennis said, I did not
do that in the way you did, so maybe he uses 2002

Cor

"Nak" <[email protected]>

..
 
NIck, thanks for confirmimg that I'm not going nuts. I get the same result
and I'm running VS.Net 2003. It must be a bug in the Designer code.
 
Hi Dennise,

Yeah, I suppose what the designer *should* do is when you add a listview
item, automatically create a sub item with the same value. I always thought
this was a little stupid when setting or getting the sub items in code,
subitem(0) should be the second column really.

Have you come across the designer bug with the tab control yet? This is
most annoying, if you have enough tabs that you need to scroll to access
one, upon closing the form it seems to jumble the order of the tabs up, the
only way to rectify it is to edit the designer code manually.

Nick.
 
Dennis,

I do not have this behaviour at all, so you can not call it a bug in the
Desinger code from 2003, it works as it should work, not in a different way
for me.

I get the result when I do what I told in the message to Nick, and that is
exactly as it should be.

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

Back
Top