Using a listbox to change focus between forms.

EStallworth

Well-known member
Joined
Aug 14, 2006
Messages
75
Location
Destin, FL
Programming Experience
Beginner
I have an multiform application that lists the open forms (by name[text]) in a listbox on the main form. As a new form is opened a string representing that form is sent to the listbox. What I am trying to do is set it so that when the selected index changes, between form names, that particular form is brought into focus. Can anyone help?¿ I've looked through some other threads and haven't quite found what I am looking for. At first I used:

VB.NET:
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged

     If listbox1.selectedindex.Equals("Return History") Then

          Dim history As New ReturnHistory(ListBox1, MenuItem4, pw)
          history.Show()
 
     End If
               
End Sub

But of course this gives me a new instance and not the current form being used.
 
Application.OpenForms("formname").Activate() could be it.
 
I tried, to no avail. I will have to do some more research. Thx for the effort though!:)
 
You get a NullReferenceException if there is no open form with that Name, else it works even case insensitive. It also works both for regular multiple forms and Mdi, so I don't quite understand your failure.
 
You get a NullReferenceException if there is no open form with that Name, else it works even case insensitive. It also works both for regular multiple forms and Mdi, so I don't quite understand your failure.

Yeah my bad. What I was doing was checking the selectedindex within my If statement when I should have been using selecteditem. LOL. Thx dude.
 
Back
Top