Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 2012 > BOOK: Visual Basic 2012 Programmer's Reference
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Visual Basic 2012 Programmer's Reference
This is the forum to discuss the Wrox book Visual Basic 2012 Programmer's Reference by Rod Stephens; ISBN: 978-1-1183-1407-4
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Visual Basic 2012 Programmer's Reference section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old December 6th, 2012, 04:41 PM
Authorized User
Points: 193, Level: 3
Points: 193, Level: 3 Points: 193, Level: 3 Points: 193, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2011
Posts: 31
Thanks: 6
Thanked 0 Times in 0 Posts
Question Adding Sub Items to List View

Hi Rod,

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.

Can you tell me where I am going wrong?


I look forward to your reply and as always, I really appreciate your help.


Sincerely,


Gary


The code for my work is below:

Code:
Public Class Form1

    Private Sub btnAddDescription_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddDescription.Click

        'Defines the Index Variable
        Dim Index As Integer
        Index = txtIndex.Text

        'Defines the Items Variable
        Dim Items As String
        Items = txtItems.Text

        'Defines the Description Variable
        Dim Description As String
        Description = txtDescription.Text



        'Adds an image to the first column without any string of text and Adds Text from TextBox1
        Dim objListItem As ListViewItem
        objListItem = lstMyListView.Items.Add("", Index)
        objListItem.SubItems.Add(Items)


        Dim objListItem2 As ListViewItem
        objListItem2 = lstMyListView.Items.Add(Items)
        objListItem2.SubItems.Add(Description)




    End Sub


End Class
Reply With Quote
  #2 (permalink)  
Old May 20th, 2013, 11:25 AM
Rod Stephens's Avatar
Wrox Author
Points: 3,145, Level: 23
Points: 3,145, Level: 23 Points: 3,145, Level: 23 Points: 3,145, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 641
Thanks: 2
Thanked 96 Times in 95 Posts
Default

Sorry for the long delay. I missed this post.

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

Code:
         Items
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

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

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


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
adding Dropdown list Items from SQLSERVER 2005 database biswa Pro VB Databases 1 October 23rd, 2009 10:46 AM
Help Grid View Drop Down List, view all jskinner123 ASP.NET 2.0 Basics 0 November 25th, 2007 05:25 PM
populate details view or list view non empty rows iinfoque ASP.NET 2.0 Basics 0 March 11th, 2007 06:11 AM
adding items to list box using javascript k.manisha ASP.NET 1.0 and 1.1 Professional 3 February 16th, 2007 05:32 AM
fill dropdown list with items when parent list isaac_cm Pro PHP 1 July 10th, 2006 05:41 AM



All times are GMT -4. The time now is 03:18 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.