View Single Post
  #2 (permalink)  
Old May 20th, 2013, 11:25 AM
Rod Stephens's Avatar
Rod Stephens Rod Stephens is offline
Wrox Author
Points: 3,166, Level: 23
Points: 3,166, Level: 23 Points: 3,166, Level: 23 Points: 3,166, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jan 2006
Location: , , .
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts

Sorry for the long delay. I missed this post.

I am working with the ListView Control and I have three columns. In my first column I have placed an image. In the second column I have placed some text as a sub item. So far so good. My difficulty is in placing text in the third column.

I know that by default, if an image is added it appears in the first column with the first list item to its right in the same column. I do not want text in the first column so I added an empty string like lstMyListView.Items.Add("",0) . Anyway that part works fine.

My difficulty is in adding a second sub item which should go in the third column. When I run the code as shown below, it properly places the image in the first column, the text from txtItems.text in the second column. However, it places the text from txtDescription.text in the second column one line below rather than in the adjacent third column.
I think it's doing what your code is telling it to do.

First you create an item with text "" and a sub-item.

Then you create another item with text given by the Items variable and a sub-item with text given by the Description variable.

The result is the control's first row displays the first item (empty string Items). The second row displays the Items plus Description:

Items    Description
It looks like Description is part of Items above but really the control is displaying the items by rows not columns.

Let me know if that doesn't help.

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
Reply With Quote