• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 502
  • Last Modified:

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.
0
vvandevender
Asked:
vvandevender
  • 6
  • 5
1 Solution
 
tpwellsCommented:
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
0
 
Bob LearnedCommented:
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
0
 
vvandevenderAuthor Commented:
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.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
Bob LearnedCommented:
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
0
 
vvandevenderAuthor Commented:
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.
0
 
Bob LearnedCommented:
That code would go into the form where the controls are defined.

Bob
0
 
vvandevenderAuthor Commented:
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?
0
 
Bob LearnedCommented:
I would add the save code event handler that detect the changes for the DriveListBox and DirListBox.

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

0
 
vvandevenderAuthor Commented:
Is this save code event handler something I have to type manually in or is it in the Toolbox?
0
 
Bob LearnedCommented:
You probably need a sample:

1) Create a form -- Form1
2) Drop a DriveListBox on the form -- DriveListBox1
3) Drop a DirListBox on the form -- DirListBox1
4) View the code module
5) Paste in this code:
  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    If My.Settings.DriveListBoxDrive.Length > 0 Then
      Me.DriveListBox1.Drive = My.Settings.DriveListBoxDrive
    End If

    If My.Settings.DirListBoxPath.Length > 0 AndAlso Me.DriveListBox1.Drive.Substring(0, 2).Equals(My.Settings.DirListBoxPath.Substring(0, 2), StringComparison.OrdinalIgnoreCase) Then
      Me.DirListBox1.Path = My.Settings.DirListBoxPath
    End If

  End Sub

  Private Sub DriveListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DriveListBox1.SelectedIndexChanged

    If Me.Visible Then
      Me.DirListBox1.Path = Me.DriveListBox1.Drive.Substring(0, 2)

      My.Settings.DriveListBoxDrive = Me.DriveListBox1.Drive
      My.Settings.Save()
    End If

  End Sub

  Private Sub DirListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DirListBox1.SelectedIndexChanged

    If Me.Visible Then
      My.Settings.DirListBoxPath = Me.DirListBox1.DirList(Me.DirListBox1.DirListIndex)
      My.Settings.Save()
    End If

  End Sub

5) To add code to the event handler for a control, select the control on the designer, and look at the Properties window.  There will be a lightning bolt with an 'Events' tooltip.  When you click on the button, you will see all the events for the control.  Find the one that you need, and double-click in the blank space to the right of the event name to get an event handler created in the code module.

Bob
0
 
vvandevenderAuthor Commented:
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.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now