Results 1 to 4 of 4

Thread: [RESOLVED] ListView box hell

  1. #1

    Thread Starter
    Hyperactive Member Jenova's Avatar
    Join Date
    Feb 2006
    Location
    Googleplex
    Posts
    413

    Resolved [RESOLVED] ListView box hell

    Hello,

    I have been trying to get this to work for a long time and it has started to get on my nerves on more than one occasion.

    Everyone knows how use a listbox, when you add an item i.e

    VB Code:
    1. Private Sub Command1_Click()
    2.        
    3.        List1.AddItem Text1.Text
    4.        Text1.Text = ""
    5.  
    6. End Sub

    This will add a text boxes text to the list box over again. So you will have more than 1 item in the list box.

    How do i do this with a ListView box. i have included the form file below. I need to add 3 items from 3 text boxes into 3 coloumns.

    Please Help

    Jenova
    Attached Files Attached Files

  2. #2
    Frenzied Member oh1mie's Avatar
    Join Date
    Sep 2001
    Location
    Finland
    Posts
    1,043

    Re: ListView box hell

    Remove all columns what you set on custom mode.
    You can do them by code

    I did leave for next statements for sample view.

    VB Code:
    1. Private Sub Form_Load()
    2.    
    3.     Dim i As Integer
    4.    
    5.     With ListView1
    6.         .ColumnHeaders.Add(, , "Id").Tag = "Id"
    7.         .ColumnHeaders.Add(, , "Text1").Tag = "Text1"
    8.         .ColumnHeaders.Add(, , "Text2").Tag = "Text2"
    9.         .ColumnHeaders.Add(, , "Text3").Tag = "Text3"
    10.    
    11.         .ColumnHeaders(1).Width = 0
    12.         .ColumnHeaders(2).Width = 2000
    13.         .ColumnHeaders(3).Width = 2000
    14.         .ColumnHeaders(4).Width = 2000
    15.        
    16.         .ColumnHeaders(2).Alignment = lvwColumnLeft
    17.         .ColumnHeaders(3).Alignment = lvwColumnCenter
    18.         .ColumnHeaders(4).Alignment = lvwColumnRight
    19.         .SortKey = 2
    20.         .Sorted = True
    21.         .BorderStyle = ccFixedSingle
    22.         .View = lvwReport
    23.     End With
    24.    
    25.     Text1 = "Sampletext 1"
    26.     Text2 = "Sampletext 2"
    27.     Text3 = "Sampletext 3"
    28.    
    29.     ListView1.ListItems.Clear
    30.     With ListView1
    31.         With .ListItems
    32.             For i = 1 To 1
    33.                 With .Add(, , CStr(i))
    34.                     .ListSubItems.Add , , Text1
    35.                     .ListSubItems.Add , , Text2
    36.                     .ListSubItems.Add , , Text3
    37.                 End With
    38.             Next
    39.         End With
    40.     End With
    41.  
    42. End Sub
    oh1mie/Vic


  3. #3
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: ListView box hell

    The ListView contains a collection called ListItems. Use it to add new ListItem objects to the listview. A ListItem is the data for Column 1 in Report View.

    The ListItem contains a collection called ListSubItems. Use it to add new ListSubItem objects to the ListItem. A ListSubItem is the data for the other columns.

    You can also use the ListItem.SubItems array

    VB Code:
    1. Dim oNewItem As ListItem
    2.    
    3.     Set oNewItem = ListView1.ListItems.Add(, , Text1.Text)
    4.  
    5.     oNewItem.ListSubItems.Add , , Text2.Text
    6.     oNewItem.ListSubItems.Add , , Text3.Text
    7.     'or
    8.     oNewItem.SubItems(1) = Text2.Text
    9.     oNewItem.SubItems(2) = Text3.Text

  4. #4

    Thread Starter
    Hyperactive Member Jenova's Avatar
    Join Date
    Feb 2006
    Location
    Googleplex
    Posts
    413

    Re: ListView box hell

    Thank you Soo much

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