Link to home
Start Free TrialLog in
Avatar of vvandevender
vvandevender

asked on

Making a drivelistbox and a dirlistbox automatically go to the drive you selected on your previous log in. Visual Basic 2005

                                                                  Visual Basic 2005 Express

I need to know how to make a drivelistbox and a dirlistbox remember the drive you used on your last log in. I am new to vb and this is my first windows application. I have searched on google and found nothing. My users has so many drives mapped on there drives. The two boxes are working together right now. When the user clicks on a drive the dirlistbox displays the folders inside that drive. I need the application to remember what drive and folder the user used on there previous log in and automatically go there when application starts. I am sure this is a common command and I can't believe I did not find what I was looking for on google.
Avatar of tpwells
tpwells

There is a not a command to do this, however what you can do is store the currently selected values to a file and on load of the application check for this file and load the last selected values to the listboxes
Avatar of Bob Learned
Since you are creating a Windows application, you can use My.Settings to store application and user settings.  You could add a string user setting to save the last drive and path.

Bob
Avatar of vvandevender

ASKER

I am liking bob's approach. Would I do this under my drivelistbox or my dirlistbox code ?

Being new to this and taking a wild guess would the syntax be like this

My.Settings( string to save path inside here ) ?

I am not familiar with "string user settings" as well could you give me an example of that please.

I am totally clueless on this matter.
Steps:

1) Right click on the project in the Solution Explorer

2) Select the 'Settings' tab.

3) Enter in name=DriveListBoxDrive, type=String, scope=User
                  name=DirListBoxPath, type=String, scope=User

4) Save the changes

5) In your code, do something like this:

    driveListBox.Drive = My.Settings.DriveListBoxDrive
    dirListBox.Path = My.Settings.DirListBoxPath

6) To update the settings, do something like this:

    My.Settings.DriveListBoxDrive = driveListBox.Drive
    My.Settings.DirListBoxPath = dirListBox.Path
    My.Settings.Save()

Bob
Ok added the two names to the setting tab. I notice that you are able to get to some code from the setting tab. When you say add the code are you meaning add it in the Mysetting code or the project code. It looks like you can add code in two different places so I was just checking to see which one you are talking about.
That code would go into the form where the controls are defined.

Bob
Ok i added all of that code except the update code under the Private sub DriveListBox1 sub routine.  Wouldn't I need to add the update settings code above the other code you showed me?
I would add the save code event handler that detect the changes for the DriveListBox and DirListBox.

Bob
Can you manually add an event without having to double click on the design view ?

Is this save code event handler something I have to type manually in or is it in the Toolbox?
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That worked.  Thanks I learned alot from that. I went through it several times and I see and understand what you are doing there.  Thank you so much and I apoligize for being so clueless, and you having to pretty much spell it out for me, but I am learning as I go here.  This is much cooler than the mainframe I must say.  Hopefully, after a short time period of working with Visual Basic, I won't be on here so much asking questions.