Results 1 to 8 of 8

Thread: Unable to add columns

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2009
    Posts
    3

    Unable to add columns

    Hi all,

    I am trying to use the list view control. Everything works fine except adding columns.
    I found this code on net and trying adding columns. However, it adds only 1 column. I just could not understand the reason for it. Please help.

    Private Sub Form_Load()
    Dim column_header As ColumnHeader
    Dim list_item As ListItem

    ' Create the column headers.
    Set column_header = ListView1. _
    ColumnHeaders.Add(, , "Abbrev", _
    TextWidth("Abbrev"))
    Set column_header = ListView1. _
    ColumnHeaders.Add(, , "Title", _
    TextWidth("Ready-to-Run Visual Basic Algorithms"))
    Set column_header = ListView1. _
    ColumnHeaders.Add(, , "ISBN", _
    TextWidth("0-000-00000-0"))

    ' Start with report view.
    mnuViewChoice_Click lvwReport

    ' Associate the ImageLists with the
    ' ListView's Icons and SmallIcons properties.
    ListView1.Icons = imgLarge
    ListView1.SmallIcons = imgSmall

    Set list_item = ListView1.ListItems.Add(, , "VBA")
    list_item.Icon = 1
    list_item.SmallIcon = 1
    list_item.SubItems(1) = "Ready-to-Run Visual Basic " & _
    "Algorithms"
    list_item.SubItems(2) = "0-471-24268-3"

    Set list_item = ListView1.ListItems.Add(, , "VBGP")
    list_item.Icon = 1
    list_item.SmallIcon = 1
    list_item.SubItems(1) = "Visual Basic Graphics " & _
    "Programming"
    list_item.SubItems(2) = "0-471-15533-0"

    Set list_item = ListView1.ListItems.Add(, , "CCL")
    list_item.Icon = 1
    list_item.SmallIcon = 1
    list_item.SubItems(1) = "Custom Controls Library"
    list_item.SubItems(2) = "0-471-24267-5"

    Set list_item = ListView1.ListItems.Add(, , "AVBT")
    list_item.Icon = 1
    list_item.SmallIcon = 1
    list_item.SubItems(1) = "Advanced Visual Basic " & _
    "Techniques"
    list_item.SubItems(2) = "0-471-18881-6"
    End Sub

    Thanks,

    Sushant

  2. #2
    Junior Member
    Join Date
    Oct 2009
    Posts
    16

    Re: Unable to add columns

    Hi, just right click on your ListView, click Properties then select the "Column Headers" tab, you can set your columns easier there.

  3. #3
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: Unable to add columns

    ' Create the column headers.
    Set column_header = ListView1. _
    ColumnHeaders.Add(, , "Abbrev", _
    TextWidth("Abbrev"))
    Set column_header = ListView1. _
    ColumnHeaders.Add(, , "Title", _
    TextWidth("Ready-to-Run Visual Basic Algorithms"))
    Set column_header = ListView1. _
    ColumnHeaders.Add(, , "ISBN", _
    TextWidth("0-000-00000-0"))
    The above code adds the 3 column headers (means columns)....

    Can you point out what exactly you want or what is the error???

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  4. #4
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: Unable to add columns

    Hi, just right click on your ListView, click Properties then select the "Column Headers" tab, you can set your columns easier there.
    Greeny is right. But if you want to add the columns at runtime, then the code in the first post is useful...

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  5. #5

    Thread Starter
    New Member
    Join Date
    Oct 2009
    Posts
    3

    Question Re: Unable to add columns

    Hi,

    The problem here is, althogh i know I have added the columns. But as per the code, the data should go into repective columns.

    Nothing as such happens.

    I get the output as

    VBA VBGP CCL AVBT

    But I guess, it should appear as

    VBA Ready-to-Run Visual Basic Algorithms 0-471-24268-3
    VBGP Visual Basic Graphics Programming 0-471-15533-0
    CCL Custom Controls Library 0-471-24267-5
    ABVT Advanced Visual Basic Techniques 0-471-18881-6

    Please help.

    Regards,
    Sushant

  6. #6
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: Unable to add columns

    Change the View property of Listview1 to lvwReport

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  7. #7

    Thread Starter
    New Member
    Join Date
    Oct 2009
    Posts
    3

    Re: Unable to add columns

    Hi,

    Thanks a lot Abhishek.

    U solved my problem.

    Sushant

  8. #8
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: Unable to add columns

    Hi,

    Thanks a lot Abhishek.

    U solved my problem.

    Sushant
    Not Abhishek , it is Akhilesh..... Akhilesh B Chandran

    Happy to hear that...

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width