|
-
Dec 20th, 2003, 04:32 AM
#1
Thread Starter
Fanatic Member
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.
-
Dec 20th, 2003, 04:34 AM
#2
Supreme User
You would need some kind of Array for that. To correctly identify which item has been clicked
-
Dec 20th, 2003, 04:36 AM
#3
Thread Starter
Fanatic Member
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.
-
Dec 20th, 2003, 04:40 AM
#4
Supreme User
You mean to delete the item from the list?
Not sure on the syntax, but something like:
VB Code:
List1.ListItems.Remove (List1.Selected.Index)
I think its something like that, ill have a look in a bit if it doesnt work..
-
Dec 20th, 2003, 04:43 AM
#5
Supreme User
Oops, i was looking at ListView. here is your code:
VB Code:
List1.RemoveItem (Selected)
-
Dec 20th, 2003, 04:47 AM
#6
Thread Starter
Fanatic Member
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.
-
Dec 20th, 2003, 04:49 AM
#7
Supreme User
It should do it automatically i think
-
Dec 20th, 2003, 04:52 AM
#8
Thread Starter
Fanatic Member
C#.net, VB, C++, Java, VS 2005/2008
Dont' forget to rate posts that are helpful to you.
-
Dec 20th, 2003, 04:54 AM
#9
Supreme User
No problems, if it doesnt select it automatically (which im sure it does), you just need to set focus on the List1.Index property.
-
Dec 20th, 2003, 05:01 AM
#10
Thread Starter
Fanatic Member
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.
-
Dec 20th, 2003, 05:03 AM
#11
Supreme User
Try something like:
VB Code:
List1.Selected(0)
'Where (0) is the List Index
-
Dec 20th, 2003, 05:11 AM
#12
Thread Starter
Fanatic Member
This is my code.
VB Code:
Private Sub Command1_Click()
Dim sFile As String
CommonDialog1.Filter = "Text (*.txt) | *.txt"
CommonDialog1.CancelError = False
CommonDialog1.ShowOpen
sFile = CommonDialog1.FileName
If Len(sFile) > 0 Then
OpenFile List1, sFile
End If
End Sub
Private Sub Command3_Click()
Dim iCnt As Integer
Open "C:\list.txt" For Output As #1
For iCnt = 0 To List2.ListCount - 1
Print #1, List2.List(iCnt)
Next
Close #1
Shell "Notepad.exe C:\list.txt", vbNormalFocus
End Sub
Private Sub Command4_Click()
Timer1.Enabled = True
End Sub
Private Function OpenFile(lstBox As ListBox, FileName As String) As String
Dim FF As Integer
Dim sString As String
FF = FreeFile
Open FileName For Input As #FF
Do Until EOF(FF)
Line Input #FF, sString
If sString <> "" Then
lstBox.AddItem sString
End If
Loop
Close #FF
End Function
Private Sub Timer1_Timer()
While List1.ListCount > 0
List2.AddItem ("List1.AddItem (Text1.Text & "" & List1.Text & "")")
List1.RemoveItem (Selected)
List1.Selected (0)
Wend
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.
-
Dec 20th, 2003, 05:17 AM
#13
Supreme User
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:
List1.Selected (0) = True
for example
-
Dec 20th, 2003, 05:18 AM
#14
Thread Starter
Fanatic Member
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.
-
Dec 20th, 2003, 08:05 AM
#15
Lively Member
Like Madboy said:
... works perfectly
Anticipation of death is worse than death itself
-
Dec 20th, 2003, 08:24 AM
#16
Supreme User
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|