Login or Sign up Help | Site Map
Connecting Tech Pros Worldwide

question about directory list boxes

Question posted by: Antony Clements (Guest) on December 25th, 2006 11:45 PM
i have written a program that incorporates the following code.

Private Sub Dir1_Change()
'changes the folder and displays each file in the folder
On Error Resume Next
File1.Path = Dir1.Path
RaiseEvent DirectoryChanged(Dir1.Path)
File1.Selected(0) = True
frmMain2.lblFileIn.Caption = Dir1.Path
frmMain2.lblFileOut.Caption = Dir1.Path
End Sub

is there any way i can modify this code to also work with a keypress event?

i have tried the following, but it doesn't work.

Private Sub Dir1_KeyPress(KeyAscii As Integer)
On Error Resume Next
If KeyAscii = vbKeyReturn Then
File1.Path = Dir1.Path
RaiseEvent DirectoryChanged(Dir1.Path)
File1.Selected(0) = True
frmMain2.lblFileIn.Caption = Dir1.Path
frmMain2.lblFileOut.Caption = Dir1.Path
End If
End Sub


Would you like to answer this question?
Sign up for a free account, or Login (if you're already a member).
J French's Avatar
J French
Guest
n/a Posts
December 26th, 2006
06:15 AM
#2

Re: question about directory list boxes
See inline :-

On Tue, 26 Dec 2006 11:38:01 +1100, "Antony Clements"
<antony.clements@optusnet.com.auwrote:
Quote:
Originally Posted by
>i have written a program that incorporates the following code.
>
>Private Sub Dir1_Change()
'changes the folder and displays each file in the folder
On Error Resume Next
File1.Path = Dir1.Path
RaiseEvent DirectoryChanged(Dir1.Path)
File1.Selected(0) = True
frmMain2.lblFileIn.Caption = Dir1.Path
frmMain2.lblFileOut.Caption = Dir1.Path
>End Sub
>
>is there any way i can modify this code to also work with a keypress event?
>
>i have tried the following, but it doesn't work.
>
>Private Sub Dir1_KeyPress(KeyAscii As Integer)
On Error Resume Next
If KeyAscii = vbKeyReturn Then

Dir1.Path = Dir1.List(Dir1.ListIndex) '<=== Add This ===
Quote:
Originally Posted by
File1.Path = Dir1.Path
RaiseEvent DirectoryChanged(Dir1.Path)
File1.Selected(0) = True
frmMain2.lblFileIn.Caption = Dir1.Path
frmMain2.lblFileOut.Caption = Dir1.Path
End If
>End Sub


The highlighted Directory is NOT the selected Directory, that only
happens with a double click.

If I were you I would wrap this in a UserControl, it is the sort of
thing that you will probably want to re-use.




Antony Clements's Avatar
Antony Clements
Guest
n/a Posts
December 26th, 2006
10:25 AM
#3

Re: question about directory list boxes
thanks for that J French

"J French" <erewhon@nowhere.ukwrote in message
news:4590c92b.1274040@news.btopenworld.com...
Quote:
Originally Posted by
See inline :-
>
On Tue, 26 Dec 2006 11:38:01 +1100, "Antony Clements"
<antony.clements@optusnet.com.auwrote:
>
Quote:
Originally Posted by
>>i have written a program that incorporates the following code.
>>
>>Private Sub Dir1_Change()
> 'changes the folder and displays each file in the folder
> On Error Resume Next
> File1.Path = Dir1.Path
> RaiseEvent DirectoryChanged(Dir1.Path)
> File1.Selected(0) = True
> frmMain2.lblFileIn.Caption = Dir1.Path
> frmMain2.lblFileOut.Caption = Dir1.Path
>>End Sub
>>
>>is there any way i can modify this code to also work with a keypress
>>event?
>>
>>i have tried the following, but it doesn't work.
>>
>>Private Sub Dir1_KeyPress(KeyAscii As Integer)
> On Error Resume Next
> If KeyAscii = vbKeyReturn Then

Dir1.Path = Dir1.List(Dir1.ListIndex) '<=== Add This ===
Quote:
Originally Posted by
> File1.Path = Dir1.Path
> RaiseEvent DirectoryChanged(Dir1.Path)
> File1.Selected(0) = True
> frmMain2.lblFileIn.Caption = Dir1.Path
> frmMain2.lblFileOut.Caption = Dir1.Path
> End If
>>End Sub

>
The highlighted Directory is NOT the selected Directory, that only
happens with a double click.
>
If I were you I would wrap this in a UserControl, it is the sort of
thing that you will probably want to re-use.
>
>
>




 
Not the answer you were looking for? Post your question . . .
184,013 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
  • Didn't find the answer you were looking for?
    Post Your Question
  • Top Community Contributors