Results 1 to 5 of 5

Thread: [Resolved] ListView Strange Problem =S

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    Resolved [Resolved] ListView Strange Problem =S

    I have another problem.

    I'm using the list view to show data from a file.
    It splits it up into columns and cell etc etc

    A Strange thing happens when i clear the listview and then reload the data into it (a refresh options). It's for a game by the way.

    The following happens.. say this is my table here

    ("" is the next cell, i didn't want to post a pic too long)

    Snail "" 5/0 "" 4 "" 6 "" 00001
    Slime "" 6/7 "" 3 "" 7 "" 00002
    Something Else "" 1/2 "" 6 "" 7 "" 0003

    I use the same code to reload the listview from the file, i just use the ListView.Clear function before reloading the data.

    Slime "" "" "" ""
    Something Else "" "" "" ""
    Snail "" 1/2 "" 6 "" 7 "" 0003

    They load in what looks like reverse, but only the bottom stats for the monster shows up and its not even for the monster (the names rearrange).

    If you want a screen shot, i can provide it
    Here's the code:

    VB Code:
    1. Private Sub Form_Load()
    2.  
    3. LstMonster.ListItems.Clear
    4. Load_Monsters LstMonster
    5.  
    6. End Sub
    7.  
    8. 'The Loading sub
    9.  
    10. Public Sub Load_Monsters(List_ As ListView)
    11.  
    12. List_.ListItems.Clear
    13.  
    14. DoEvents
    15.  
    16. Dim Monsters_() As String
    17. Dim MStats_() As String
    18. Dim SText As String
    19. Dim I As Integer
    20.  
    21. SText = ""
    22. I = 0
    23.  
    24. Open "MonsterList.txt" For Input As #1
    25. SText = Input(LOF(1), #1)
    26. Close #1
    27.  
    28. Monsters_ = Split(SText, "|MSplit|")
    29.  
    30. List_.SortKey = Left(Monsters_(0), 2)
    31.  
    32. For I = 1 To UBound(Monsters_)
    33.  
    34. Mstats = Split(Monsters_(I), "|LSplit|")
    35.  
    36. List_.ListItems.Add , , Mstats(0)
    37. List_.ListItems.Item(I).SubItems(1) = Trim(Mstats(1))
    38. List_.ListItems.Item(I).SubItems(2) = Trim(Mstats(2))
    39. List_.ListItems.Item(I).SubItems(3) = Trim(Mstats(3))
    40. List_.ListItems.Item(I).SubItems(4) = Trim(Mstats(4))
    41. List_.ListItems.Item(I).SubItems(5) = Trim(Left(Mstats(5), 5))
    42.  
    43. Next I
    44.  
    45. List_.Sorted = True
    46.  
    47. End Sub
    48.  
    49. 'Here's the refresh code that i use (just reload because the clear is in the load code)
    50.  
    51. Private Sub Refresh_Click()
    52.  
    53. Load_Monsters LstMonster
    54.  
    55. end sub
    Last edited by Hack; Jun 2nd, 2006 at 08:33 AM. Reason: Added green "resolved" checkmark Last edited by Slyke : Today at 09:31 AM.

  2. #2
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: ListView Strange Problem =S

    Can you attach the file "MonsterList.txt" ?? so we can "play" with it?
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    Re: ListView Strange Problem =S

    ok, here it is.
    Attached Files Attached Files

  4. #4
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: ListView Strange Problem =S

    ok do it like this (Using a ListItem Object)

    VB Code:
    1. Public Sub Load_Monsters(List_ As ListView)
    2.     List_.ListItems.Clear
    3.     DoEvents
    4.     Dim Monsters_() As String
    5.     Dim MStats_() As String
    6.     Dim SText As String
    7.     [B]Dim LI As ListItem[/B]
    8.     Dim I As Integer
    9.     SText = ""
    10.     I = 0
    11.     Open "C:\MonsterList.txt" For Input As #1
    12.         SText = Input(LOF(1), #1)
    13.     Close #1
    14.     Monsters_ = Split(SText, "|MSplit|")
    15.     List_.SortKey = Left(Monsters_(0), 2)
    16.     For I = 1 To UBound(Monsters_)
    17.         Mstats = Split(Monsters_(I), "|LSplit|")
    18.         [B]Set LI = List_.ListItems.Add(, , Mstats(0))[/B]
    19.         [B]LI.SubItems(1) = Trim(Mstats(1))
    20.         LI.SubItems(2) = Trim(Mstats(2))
    21.         LI.SubItems(3) = Trim(Mstats(3))
    22.         LI.SubItems(4) = Trim(Mstats(4))
    23.         LI.SubItems(5) = Trim(Left(Mstats(5), 5))[/B]
    24.     Next I
    25.     List_.Sorted = True
    26. End Sub

    your code didnt seem to add the subitems to the right things? odd.. but this worked
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    Re: ListView Strange Problem =S

    Thanks! It works great now.

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