Results 1 to 11 of 11

Thread: VB6 - Listview vertically?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2012
    Posts
    23

    VB6 - Listview vertically?

    Hello I was playing around with listviews (new to vb) and from what I understand is that the item is placed to the far left then the sub items are then listed to the right of it. Is there anyway to make list them vertically? Basically making the item the header

    Example:

    Food <- Item
    Cookies <- subitem
    apples
    pizza
    ...etc

    Thanks!
    JO

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: VB6 - Listview vertically?

    Make "Food" a column header not a listview item.

  3. #3
    Frenzied Member
    Join Date
    Mar 2008
    Posts
    1,210

    Re: VB6 - Listview vertically?

    While I confess to never having used one it sounds like it may be a job for the TreeView Control.

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Sep 2012
    Posts
    23

    Re: VB6 - Listview vertically?

    Thanks for the reply. Sorry I should explain more. There are going to be multiple columns with multiple rows. The user fills out a form clicks done then a new form appears with a list view consisting of data from the previous form. So the list will get populated at runtime.

    Hack I'm not sure how that would work with what I'm trying to do but thanks for the suggestion.

    Magic thanks for the suggestion I will play around with tree view and post what my results are

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Sep 2012
    Posts
    23

    Re: VB6 - Listview vertically?

    Tree view isnt what I am looking for. It's more of taking the rows generated by list view and making them into columns. I'll keep looking into it and repost when I find a solution. Any other suggestions, tips or other methods I could use are always welcome. Thanks for the help!

    JO

  6. #6
    PowerPoster
    Join Date
    Aug 2011
    Location
    B.C., Canada
    Posts
    2,887

    Re: VB6 - Listview vertically?

    The only way is to make first item like a header but it will not look like a header it will only look like an item

  7. #7
    PowerPoster
    Join Date
    Aug 2011
    Location
    B.C., Canada
    Posts
    2,887

    Re: VB6 - Listview vertically?

    Make a demo list your first list looks like it is going to be horizontal

    Pizza - Cheese - Pepperoni
    Cake - Flour - Eggs

    But you would like to have it like this????

    Pizza - Cake
    Cheese - Flour
    Pepperoni - Eggs

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Sep 2012
    Posts
    23

    Re: VB6 - Listview vertically?

    correct

  9. #9
    PowerPoster
    Join Date
    Aug 2011
    Location
    B.C., Canada
    Posts
    2,887

    Re: VB6 - Listview vertically?

    ok here is a small example i want to show you add this to a new form with only 1 listview name "ListView1"

    Code:
    Option Explicit
    
    Private Const Items_Limit As Integer = 5
    Private Const SubItems_Limit As Integer = 6
    Private Const lvHeight As Integer = 210
    
    Private ItemCount As Integer
    
    Private Sub TestSub()
    Add_ListItem "Item1", "One,Two,Three,Four,Five"
    Add_ListItem "Pizza", "Cheese,Pepperoni,Mushrooms,Onions,Olives"
    Add_ListItem "Item3", "Sub-One,Sub-Two,Sub-Three,Sub-Four,Sub-Five"
    Add_ListItem "Item4", "1,2,3,4,5"
    Add_ListItem "Item5", "One,Two,Three,Four,Five"
    End Sub
    
    Private Sub Form_Load()
    Dim i As Integer
    
    Me.Width = 9000
    Me.Height = 6000
    ListView1.View = lvwList
    ListView1.Move 0, 0, 8000, 310
    For i = 1 To Items_Limit * SubItems_Limit
    ListView1.ListItems.Add , , i
    Next
    
    ListView1.Height = 310 + (lvHeight * Items_Limit)
    
    For i = 1 To Items_Limit
      ListView1.ListItems.Item(i).Bold = True
    Next
    
    'All done loading items
    
    TestSub
    End Sub
    
    
    
    Private Sub Add_ListItem(ItemName As String, SubItems As String)
    Dim i As Integer
    Dim sSubItems() As String
    
    If ItemCount >= Items_Limit Then
    MsgBox "Listview is Full!"
    Exit Sub
    End If
    
    sSubItems = Split(SubItems, ",")
    
    If UBound(sSubItems) + 1 >= SubItems_Limit Then
    MsgBox "Too many subitems!"
    Exit Sub
    End If
    
    ItemCount = ItemCount + 1
    ListView1.ListItems.Item(ItemCount).Text = ItemName
    
    ListView1.Height = 310
    For i = 1 To UBound(sSubItems) + 1
    ListView1.ListItems(ItemCount + (i) * 5).Text = sSubItems(i - 1)
    Next
    
    ListView1.Height = 310 + (lvHeight * Items_Limit)
    End Sub
    Edit:
    I only made it for 5 items with 5 subitems for each item so 5 x 6 = 30 items/subitems total

    and i did it on the fly did not arrange code or simplify it
    Last edited by Max187Boucher; Sep 13th, 2012 at 08:17 PM.

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Sep 2012
    Posts
    23

    Re: VB6 - Listview vertically?

    thank you I will try it out and let you know how it goes!

  11. #11
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: VB6 - Listview vertically?

    If I understand OP's requirements, I think the problem is one of Transformation. e.g. changing a set of lists like:
    Code:
    Food, Cookies, Apples, Pizza, Soup, Cheese
    Drinks, Coke, Pepsi, Tea, Coffee, Root Beer, Squash
    Cakes, Eccles Cake, Bakewell Tart, Cherry Cake
    into a set of lists like this:
    Code:
    Food, Drinks, Cakes
    Cookies, Coke, Eccles Cake
    Apples, Pepsi, Bakewell Tart
    Pizza,Tea, Cherry Cake
    Soup, Coffee,
    Cheese, Root Beer,
    , Squash,
    Try the code below. Just requires a ListView named lv drawn on the Form
    Code:
    Option Explicit
    
    Private Sub Form_Load()
    Dim strTransform() As String
    Dim strMenu(2) As String
    Dim strTemp() As String
    Dim intI As Integer
    Dim intJ As Integer
    Dim intMax As Integer
    Dim lvI As ListItem
    '
    ' Lists of Items:
    '
    strMenu(0) = "Food, Cookies, Apples, Pizza, Soup, Cheese"
    strMenu(1) = "Drinks, Coke, Pepsi, Tea, Coffee, Root Beer, Squash"
    strMenu(2) = "Cakes, Eccles Cake, Bakewell Tart, Cherry Cake"
    '
    ' Required in ListView:
    '
    ' Food      Drinks      Cakes
    ' Cookies   Coke        Eccles Cake
    ' Apples    Pepsi       Bakewell Tart
    ' Pizza     Tea         Cherry Cake
    ' Soup      Coffee
    ' Cheese    Root Beer
    '           Squash
    '
    lv.View = lvwReport
    ReDim strTransform(UBound(strMenu), 10)
    For intI = 0 To UBound(strMenu)
        strTemp = Split(strMenu(intI), ",")
        For intJ = 0 To UBound(strTemp)
            If intJ > UBound(strTransform, 2) Then ReDim Preserve strTransform(UBound(strMenu), UBound(strTransform, 2) + 10)
            strTransform(intI, intJ) = strTemp(intJ)
        Next intJ
        If intJ - 1 > intMax Then intMax = intJ - 1
    Next intI
    ReDim Preserve strTransform(UBound(strMenu), intMax)
    For intI = 0 To UBound(strTransform, 1)
        lv.ColumnHeaders.Add , , strTransform(intI, 0)
    Next intI
    For intI = 1 To UBound(strTransform, 2)
        Set lvI = lv.ListItems.Add(, , strTransform(0, intI))
        For intJ = 1 To UBound(strTransform, 1)
            lvI.SubItems(intJ) = strTransform(intJ, intI)
        Next intJ
    Next intI
    End Sub
    Last edited by Doogle; Sep 14th, 2012 at 01:23 AM.

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