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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Filter Off File Extension in File List Box 1

Status
Not open for further replies.

BuckyBaby

Technical User
Sep 23, 2000
8
0
0
US
Hello,

Is there a simple way to have the displayed files in a File List Box not show the .xxx file extension to the user?

Thanks,
BuckyBaby [sig][/sig]
 
What-ho,

Here's an idea...although there MUST be a better way of doing it (I like the whole event driven-ness of this way, though) :)

For todays recipe, you will need:

A form containing;
1 x DriveListBox control
1 x DirListBox control
1 x FileListBox control
1 x ListBox control

First, set the FileListBox control Visible property to False. Although this control is neccessary, it's not going to be shown, so make it any size you like and put it anywhere on the form.

Now arrange the other three controls so that they look good to you.

Now, associate the following code with your form;

Private Sub Dir1_Change()

Me.File1.Path = Me.Dir1.Path

End Sub

Private Sub Drive1_Change()

Me.Dir1.Path = Me.Drive1.Drive

End Sub

Private Sub File1_PathChange()
Dim lngIndex As Long
Dim lngExtStart As Long

For lngIndex = 0 To Me.File1.ListCount - 1
lngExtStart = InStr(Me.File1.List(lngIndex), ".")
If lngExtStart > 0 Then
Me.List1.List(lngIndex) = Mid(Me.File1.List(lngIndex), 1, lngExtStart - 1)
Else
Me.List1.List(lngIndex) = Me.File1.List(lngIndex)
End If
Next
End Sub


What happens here is this; Changing the DriveListBox path property (by clicking on it and changing it) will raise that control's Change event, which changes the path of the DirListBox control. This, in turn, raises that control's Change event, which changes the path property of the FileListBox control.

This is where the fun stuff happens. Unfortunately, a FileListBox is read only at runtime, so you can't modify its contents. However, what you can do is assign its contents to another control - the ListBox control in this case.

The PathChange event of the FileListBox control basically says;

Loop through all the items listed here

If an item contains a . character then assign that item to the ListBox control, missing off all the characters after and including the . character

Otherwise, just assign this item to the ListBox control as is

So your ListBox control takes the place of your FileListBox control and is just as flexible a control - more so, in fact, as you can modify its contents at runtime.


The only problem is that the LitsBox control will only update if its PathChange event is raised, which doesn't appear to happen when you first launch the form. It's probably not too hard to get around this, but I've not looked into it, sorry :(


Cheerio,

Paul

[sig][/sig]
 
Paul, you made me laugh. You sound a bit like Julia Child telling us how to whip up a tasty treat.

This is a great way to start a day!

If you place your File1_PathChange code in the form's load event the list box will populate at start-up.

Good tip.
[sig]<p> <br><a href=mailto: > </a><br><a href= plain black box</a><br>"Suffice it to say that adding disk drives and a disk operating system to a personal microcomputer is guaranteed to increase its power dramatically."<br>
<u><b>CP/M and the Personal Computer</u></b>[/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top