Results 1 to 16 of 16

Thread: adding with lists

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2003
    Location
    Worcester, MA
    Posts
    782

    adding with lists

    I want to load a list from a text file into a listbox. Then i want to add text before and after the word in the list. Then add it to a new list. I can do mot of it except i dont know how to get the value of the object in the list box. For instance if it says apple i dont know to get get the computer to know that. list1.******. and i dont know how to take away the selected value and move to the next one. Can anyone help?
    C#.net, VB, C++, Java, VS 2005/2008
    Dont' forget to rate posts that are helpful to you.

  2. #2
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253
    You would need some kind of Array for that. To correctly identify which item has been clicked

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2003
    Location
    Worcester, MA
    Posts
    782
    well i figured out you can add it by doing list1.text but how do you select the first item and tae it off then go to the next?
    C#.net, VB, C++, Java, VS 2005/2008
    Dont' forget to rate posts that are helpful to you.

  4. #4
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253
    You mean to delete the item from the list?

    Not sure on the syntax, but something like:

    VB Code:
    1. List1.ListItems.Remove (List1.Selected.Index)

    I think its something like that, ill have a look in a bit if it doesnt work..

  5. #5
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253
    Oops, i was looking at ListView. here is your code:

    VB Code:
    1. List1.RemoveItem (Selected)

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2003
    Location
    Worcester, MA
    Posts
    782
    and how do i make it select the next item after it deletes?
    C#.net, VB, C++, Java, VS 2005/2008
    Dont' forget to rate posts that are helpful to you.

  7. #7
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253
    It should do it automatically i think

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2003
    Location
    Worcester, MA
    Posts
    782
    ok thanks for the help
    C#.net, VB, C++, Java, VS 2005/2008
    Dont' forget to rate posts that are helpful to you.

  9. #9
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253
    No problems, if it doesnt select it automatically (which im sure it does), you just need to set focus on the List1.Index property.

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2003
    Location
    Worcester, MA
    Posts
    782
    its not working how do you do that?
    C#.net, VB, C++, Java, VS 2005/2008
    Dont' forget to rate posts that are helpful to you.

  11. #11
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253
    Try something like:

    VB Code:
    1. List1.Selected(0)
    2. 'Where (0) is the List Index

  12. #12

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2003
    Location
    Worcester, MA
    Posts
    782
    This is my code.

    VB Code:
    1. Private Sub Command1_Click()
    2.     Dim sFile As String
    3.    
    4.     CommonDialog1.Filter = "Text (*.txt) | *.txt"
    5.     CommonDialog1.CancelError = False
    6.     CommonDialog1.ShowOpen
    7.    
    8.     sFile = CommonDialog1.FileName
    9.    
    10.     If Len(sFile) > 0 Then
    11.         OpenFile List1, sFile
    12.     End If
    13. End Sub
    14.  
    15. Private Sub Command3_Click()
    16. Dim iCnt As Integer
    17.  
    18. Open "C:\list.txt" For Output As #1
    19. For iCnt = 0 To List2.ListCount - 1
    20. Print #1, List2.List(iCnt)
    21. Next
    22. Close #1
    23.  
    24. Shell "Notepad.exe C:\list.txt", vbNormalFocus
    25. End Sub
    26.  
    27. Private Sub Command4_Click()
    28. Timer1.Enabled = True
    29. End Sub
    30.  
    31. Private Function OpenFile(lstBox As ListBox, FileName As String) As String
    32.     Dim FF As Integer
    33.     Dim sString As String
    34.  
    35.     FF = FreeFile
    36.     Open FileName For Input As #FF
    37.     Do Until EOF(FF)
    38.         Line Input #FF, sString
    39.         If sString <> "" Then
    40.             lstBox.AddItem sString
    41.         End If
    42.     Loop
    43.  
    44.     Close #FF
    45. End Function
    46.  
    47. Private Sub Timer1_Timer()
    48. While List1.ListCount > 0
    49. List2.AddItem ("List1.AddItem (Text1.Text & "" & List1.Text & "")")
    50. List1.RemoveItem (Selected)
    51. List1.Selected (0)
    52. Wend
    53. End Sub

    I get an invalid use of property on the List1.Selected(0)
    C#.net, VB, C++, Java, VS 2005/2008
    Dont' forget to rate posts that are helpful to you.

  13. #13
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253
    Yeah it does, im busy at the mo to check the correct syntax, hopefully someone else can pick up on this thread and help you

    Regards,

    P.S i forgot you treat this as a boolean value:

    VB Code:
    1. List1.Selected (0) = True

    for example

  14. #14

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2003
    Location
    Worcester, MA
    Posts
    782
    All of the syntax is correct all i need is how to select the top item in the list.
    C#.net, VB, C++, Java, VS 2005/2008
    Dont' forget to rate posts that are helpful to you.

  15. #15
    Lively Member
    Join Date
    Aug 2002
    Location
    England
    Posts
    84
    Like Madboy said:

    VB Code:
    1. List1.Selected(0) = True

    ... works perfectly
    Anticipation of death is worse than death itself

  16. #16
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253
    I would have confirmed that it worked, but i was/am really busy

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