473,388 Members | 1,417 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Showing forms from Text in Combo Boxes

OK, I have very, VERY basic background knowledge of VB6
and have now upgraded to VB.NET and now I'm struggling to
bring up the forms I want.

What I am looking to do is to have a click a command
button bring up a form, and to have which form is brought
up determined by which item is selected in the
accompanying combo box.

I've gathered that you have to declare the item as a
variable and when you want to call up that you use
Combobox1.valuemember = variable1
And then you can do what you like with it.

However my problem comes when I use more than one
variable (as you do with combo boxes).

It seems that no matter what I do:

Private Sub Butselect_Click_1(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
ButSelect.Click

CmbCharacters.ValueMember = item1
frm2.Close()
frm1.Show()
Me.Hide()

CmbCharacters.ValueMember = item2
frm1.Close()
frm2.Show()
Me.Hide()

Or put it in a Select Case or If statement I can't get it
to show the right form.
In this example both result in frm2 being shown.
I just don't get it. Any help would be greatly
appreciated.
Jul 19 '05 #1
1 3699
The first thing I see with the code below is that you're using
"ValueMember" property of the ComboBox, which is a property used when
connecting up a combo box to a datasource. I believe you'll want the
property, "Text" instead -- this will return the text currently shown on
the combo box (ie: as you select different values, the "Test" property
reflects the value currently shown when the dropdown isn't expanded).

Once you have this down, you'll run into another issue... VB.NET is object
oriented in that the form doesn't exist until you create it. In VB6, there
was automatic default instantiantion, so any forms that were part of the
project would automatically be created when you execute the program... In
VB.NET, you have to do this yourself (instanciate the form), which also
gives the added benefit of being able to create multiple instances of the
same form.

The code to create the form would look like:
Dim form1 As New Frm1
form1.Show()

This will create a new form (of type Frm1) and show it to the user. To
close the original form, you'll do something like:
Me.Hide()

NOTE: If you do, "Me.Close()", this will close the current form (destroy
it) and clean up all the resources (any additional forms you've created).

So, in the end, the code would look like (assuming the text in the combo
box are "FRM1" and "FRM2") :

Select Case ComboBox1.Text
Case "FRM1"
Dim form1 As New Frm1
form1.Show()
Me.Hide()
Case "FRM2"
Dim form1 As New Frm2
form1.Show()
Me.Hide()
Case Else
MsgBox("Unknown item selected")
End Select

If you want to use the original form to select between two other forms, the
problem gets more difficult. If you wanted to leave the original form
visible and depending on the combobox, open/close other forms, there's two
ways to do it:
1) Easy way, create a class-level variable to store the form object so you
can close it later
2) Create a collection to hold all the forms you create (so you can create
multiple instances of the same form) and close the ones depending on what's
selected.

I'll show the first one here, let me know if you'd like to see the second.
<g> I'll assume that you're starting with a VB Winforms project, newly
created in VS.
1) Add 2 new forms to the project (File -> Add New Item, and choose
Windows Form in the dialog) with the names, "FRM1" and "FRM2"
2) Drag a combo-box to the form the toolbox
3) Add two items to the combobox (properties window -> Items, click the
"..." and add "FRM1" and "FRM2" on two separate lines)
4) Drag a button to the form from the toolbox
5) Double click on the button to create the event handler
6) Add the following lines of code just after the "Inherits
System.Windows.Forms.Form" line
Dim form1 As Form
Dim form2 As Form
7) Paste the following code in the event handler for the button
Select Case ComboBox1.Text
Case "FRM1"
form1 = New Frm1
form1.Show()
If (form2 Is Nothing) = False Then
form2.Close()
End If
Case "FRM2"
form2 = New Frm2
form2.Show()
If (form1 Is Nothing) = False Then
form1.Close()
End If
Case Else
MsgBox("Unknown item selected")
End Select

Hope this helps! Let me know if you have any other questions,
Pete

--------------------
From: "Daniel Hill" <il**************@hotail.com>
Sender: "Daniel Hill" <il**************@hotail.com>
Subject: Showing forms from Text in Combo Boxes
Date: Sun, 6 Jul 2003 11:30:40 -0700
OK, I have very, VERY basic background knowledge of VB6
and have now upgraded to VB.NET and now I'm struggling to
bring up the forms I want.

What I am looking to do is to have a click a command
button bring up a form, and to have which form is brought
up determined by which item is selected in the
accompanying combo box.

I've gathered that you have to declare the item as a
variable and when you want to call up that you use
Combobox1.valuemember = variable1
And then you can do what you like with it.

However my problem comes when I use more than one
variable (as you do with combo boxes).

It seems that no matter what I do:

Private Sub Butselect_Click_1(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
ButSelect.Click

CmbCharacters.ValueMember = item1
frm2.Close()
frm1.Show()
Me.Hide()

CmbCharacters.ValueMember = item2
frm1.Close()
frm2.Show()
Me.Hide()

Or put it in a Select Case or If statement I can't get it
to show the right form.
In this example both result in frm2 being shown.
I just don't get it. Any help would be greatly
appreciated.


Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Paul Edwards | last post by:
I am writing in c# with Visual Studio 2003. I am creating a form that shows one record from a Dataset that is populated with only one record from SQL Server 2000. I am using bound controls, both...
0
by: Duncan Spence | last post by:
Hi all, I'm sure I'm doing something silly here, but can't see it! I'm creating a series of combo boxes on a Windows Form in VB.NET. The lists of all of the comboboxes are identical and are...
1
by: Daniel Hill | last post by:
OK, I have very, VERY basic background knowledge of VB6 and have now upgraded to VB.NET and now I'm struggling to bring up the forms I want. What I am looking to do is to have a click a command...
3
by: Marcus | last post by:
Something odd I just noticed on one of my forms that has a "Close MS Access button. It seems I can't use the close button if I have wrong data entered in any of the form's combo boxes. (I only have...
4
by: Miguel | last post by:
I have an order entry database with two forms. One is for new orders the other is to update orders. The forms are identical except that one is strictly order entry. On both forms are three sets of...
2
by: olblue | last post by:
I'm very new to VB.NET so basic stuff please. What I'm trying to do is this - I have a flat file of about 100,000 records. I want to display those records on a form depending on certain user...
2
by: jw01 | last post by:
I have a form in which there is one combo box and three text boxes: Combo Box: -> Item A -> Item B -> Item C TextBox1: TextBox2: ...
2
by: SHAWTY721 | last post by:
I have a form that contains two combo boxes that are related to each other. I need to find a way to populate my text box based on the criteria of the two combo boxes so the appropriate number...
1
by: bluclouds9 | last post by:
I am new to Access and have been charged with creating a database for our course alumni. I currently have a "Contacts" form and am trying to create a subform to hold the course alumni...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.