Results 1 to 7 of 7

Thread: listview columns

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2001
    Posts
    256

    listview columns

    I have a listview with three columns. I want to load a table of names into the listview, putting last names A-F in #1, G-S in #2, and T-Z in #3.

    I know how to loop through the table and load the names, but I don't know the listview code to separate the names into columns. Any ideas?

  2. #2
    Fanatic Member steve65's Avatar
    Join Date
    Jun 2000
    Posts
    610
    I use this to load values from an array I have.
    Code:
    Private Sub Form_Load()
        
    Dim i As Integer
    Dim Item As ListItem
    
        For i = 0 To UBound(Jobs)
                Set Item = lvwDayDetails.ListItems.Add(, , Jobs(i).Name)
                Item.Tag = Jobs(i).ID
                Item.ToolTipText = Jobs(i).Subject
                Item.SubItems(1) = Format(Jobs(i).NextInvocation, "hh:mm")
                Item.SubItems(2) = Jobs(i).Duration
        Next i
        
        Set Item = Nothing
    
    End Sub
    This space for rent...

  3. #3
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    Well ...

    The ListItem.Text property will give you the first column. ListItem.SubItems(1) will give you the second column, ListItem.SubItems(2) will give you the third column and so on.

    .
    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2001
    Posts
    256
    What I am looknig for is an "if...then" statement of some kind. For example, if the last name begins with "a" then put it into column #1. But I can't quite figure out the listview syntax for this logic.

    There has to be some allowance for one column being longer than the other. For example, column #3 might have 25 names, while column #1 might have 2.

  5. #5
    DerFarm
    Guest
    I think you might have to place three distinct listboxs on your
    form. You can size them to make it LOOK like they are one, but in
    reality they are different.

    Check into arrays of controls, I'v never done those but it might be
    what you want.

    Essentially, if you need to hardwire 3 columns, set up the three
    different list controls and set the recordsource with a sql query:

    select NAME from xxx where name>="A" and name<"H";

    this will get you A-G,.....

    I know this will work, but I'm not sure if there is a more elegant
    method of doing it. A multi-column listbox is supposed to be
    similar in nature to a table in that the data in column x is
    supportive and related to the data in column x+1. In your
    scheme the only relation is that they are all names. I'm not being
    very clear.....sorry.

    HTH

  6. #6
    Fanatic Member steve65's Avatar
    Join Date
    Jun 2000
    Posts
    610
    The way a listview works is each row is an Item. The first column of each row is the text of the item. Each column after that is a subitem of the first item.

    So in my example I put the Name in the first column (Item), subject in the second column (SubItem1), and duration in the last column (SubItem2).
    This space for rent...

  7. #7
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    Well ...

    Off the top of my head, use three variables, each will track how many items you have got in each column.

    Traverse through the items you have, if you find it starts from A, put it in the first column, increment first counter by 1, if it starts from G then put it in 2nd column, increment second counter by 1 and so on.

    Code:
    Count1 = 0
    Count2 = 0
    Count3 = 0
    For Each Item In YourCollection
       If Item starts with A - F
          If Count1=ListView1.ListItems.Count Then
              'Add a listitem.  It will be blank in the beginning.
              New ListItem.Text = Item
          Else
              Get ListView's Count1-th item
              Set its Text = Item.
          End If
          Count1 = Count1 + 1
       ElseIf Item starts with G - S
          If Count2=ListView1.ListItems.Count Then
              'Add a listitem.  It will be blank in the beginning.
              New ListItem.Subitems(1) = Item
          Else
              Get ListView's Count2-th item
              Set its SubItems(1) = Item.
          End If
          Count2 = Count2 + 1
        Else
          If Count3=ListView1.ListItems.Count Then
              'Add a listitem.  It will be blank in the beginning.
              New ListItem.SubItems(2) = Item
          Else
              Get ListView's Count3-th item
              Set its SubItems(2) = Item.
          End If
          Count3 = Count3 + 1
       End If
    Next Item
    That's not proper VB, but that should give you some idea.

    .
    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

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