Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to find ListIndex of items in FileListBox

Status
Not open for further replies.

princemuchao

Programmer
Dec 6, 2000
3
US
Okay, what I'm trying to do is use the filelistbox as an item that is always open in a text editor program I am creating... all text files are in the same dir as the program, so I have only a filelistbox.

The problem I am having is when someone adds a new file, I can't get the focus to change to that new text file. I assume that the way to do it would be to get the ListIndex by using the string, but I can't get it to work.

My first clumsy attempt illustrated below might illustrate what I'm trying to do a little better:

Dim strpath As String
Dim n As Integer
strpath = InputBox$("Enter new file name:")
File1.List(n) = (strpath & ".x")
Open (strpath & ".x") For Random As #1
Close #1
File1.Refresh
File1.ListIndex (n)

Any help would be greatly appreciated...
PMC
 
If you want to highlight the last entry in the list, use:

File1.ListIndex = File1.ListCount - 1

Simon
 
Normally that would work fine, but when the file gets added, it sorts them alphabetically, so the last file in the filelistbox isn't necessarily the last file added.
 
In that case, loop through the list, looking for your new file. When you find it, set the selected(i) property to True:

Dim l As Long
Dim sFile as String
' set sFile to the one you want
For l = 0 To File1.ListCount - 1
If File1.List(l) = sFile Then
File1.Selected(l) = True
Exit For
End If
Next l


Simon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top