Results 1 to 6 of 6

Thread: ListView Population... [resolved]

  1. #1

    Thread Starter
    Frenzied Member thegreatone's Avatar
    Join Date
    Aug 2003
    Location
    Oslo, Norway. Mhz:4800 x12
    Posts
    1,333

    Resolved ListView Population... [resolved]

    Ok, the following code, in theory should work... but in fact it doesn't what is wrong ?

    VB Code:
    1. Private Sub Command1_Click()
    2. CD.Filter = "Text Files (*.txt)|*.txt"
    3. Dim strData As String
    4. Dim astrDataItem() As String
    5. On Error Resume Next
    6. 'Open text file and split by :'s
    7.     CD.ShowOpen
    8.         If CD.FileName = "" Then
    9.         Else:
    10.         Open CD.FileName For Input As #1
    11.         Do Until EOF(1)
    12.         Line Input #1, strData
    13.             astrDataItem = Split(strData, ":")
    14.             ListView1.ListItems.Add 1, , astrDataItem(0)
    15.             ListView1.ListItems.Add 2, , astrDataItem(1)
    16.         Loop
    17.     Close #1
    18. End If
    19. End Sub

    CD = CommonDialog control

    Any Help would be greatly appreciated,
    Last edited by thegreatone; Mar 30th, 2005 at 12:42 PM.
    Zeegnahtuer?

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

    Re: ListView Population...

    A couple of slight modifications...
    VB Code:
    1. 'create a list item to use with your list view
    2. Dim lvwItem As ListItem
    3. Set lvwItem = ListView1.ListItems.Add 'etc
    4. 'use subitems for adding to other columns in the same row
    5.  lvwItem.SubItems(1) = 'etc

  3. #3

    Thread Starter
    Frenzied Member thegreatone's Avatar
    Join Date
    Aug 2003
    Location
    Oslo, Norway. Mhz:4800 x12
    Posts
    1,333

    Re: ListView Population...

    This doesn't seem to work, no matter what i try... it just adds a blank for the first column, and then the second split data to the second column...
    Zeegnahtuer?

  4. #4

    Thread Starter
    Frenzied Member thegreatone's Avatar
    Join Date
    Aug 2003
    Location
    Oslo, Norway. Mhz:4800 x12
    Posts
    1,333

    Re: ListView Population...

    Can anyone offer me any more help please ?
    Zeegnahtuer?

  5. #5
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: ListView Population...

    I assume your data looks something like this.

    one:two:three
    four:five:six


    If so then you may have your columns, etc set up some place else but this works.

    VB Code:
    1. Private Sub Command1_Click()
    2.  
    3.    Dim clmX As ColumnHeader
    4.    Dim itmX As ListItem
    5.  
    6.    Set clmX = ListView1.ColumnHeaders.Add(, , "1st", ListView1.Width / 3)
    7.    Set clmX = ListView1.ColumnHeaders.Add(, , "2nd", ListView1.Width / 3)
    8.    Set clmX = ListView1.ColumnHeaders.Add(, , "3rd", ListView1.Width / 3)
    9.    
    10.    
    11.    ListView1.View = lvwReport
    12.  
    13. CD.Filter = "Text Files (*.txt)|*.txt"
    14. Dim strData As String
    15. Dim astrDataItem() As String
    16. On Error Resume Next
    17. 'Open text file and split by :'s
    18.     CD.ShowOpen
    19.         If CD.FileName = "" Then
    20.         Else:
    21.         Open CD.FileName For Input As #1
    22.         Do Until EOF(1)
    23.         Line Input #1, strData
    24.             astrDataItem = Split(strData, ":")
    25.             Set itmX = ListView1.ListItems.Add(, , astrDataItem(0))
    26.             itmX.SubItems(1) = astrDataItem(1)
    27.             itmX.SubItems(2) = astrDataItem(2)
    28.         Loop
    29.     Close #1
    30. End If
    31. End Sub

  6. #6

    Thread Starter
    Frenzied Member thegreatone's Avatar
    Join Date
    Aug 2003
    Location
    Oslo, Norway. Mhz:4800 x12
    Posts
    1,333

    Re: ListView Population...

    Martin is a god for furthur explaining that
    Thanks Hack

    Pos Rep....
    Zeegnahtuer?

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