473,406 Members | 2,707 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,406 software developers and data experts.

VB2005>How to>show form2 based on combobox selection in form1?

Hi, new membership and first post. I am working in VB 2005, windows forms and would like to know how to open form2 based on the user's selection from a combobox or listbox from say, form1. Thank you, PG
Jul 18 '06 #1
6 4889
BSOB
77
PG,

listbox1_click()
if listbox1.listindex = 2 then form2.show
end sub

ok... heres how this goes. listbox1.listindex returns a value of the index of the list object that is selected (highlighted). in english:
if the first item is highlighted, listindex is 0
if the second item is highlighted, listindex is 1
(note that it starts at zero)
in my example i have listindex = 2 so it would be the third item.
only one object can be highlighted at a time if i remember corectly.

one property of a listbox is the checkbox. if you want to use the checkboxes and see if the 3rd check box is checked then the code changes to:

if Listbox1.Selected(2)= true then...

this checks the 3rd entry and its check box. (in selected(arguement) the argument is the list index that you are checking)
Im not sure how these proporties change for a combo box, and i dont feel like doing the experimenting for you.

one last thing, it will still work if you want to check the values of your listbox from some other sub. for example, if you want the user to click a button and have button1 check the listbox values, use the same code but in the button_click sub.
i just didnt want to give the impression that listindex can only be called from the listbox sub.
-bsob
Jul 18 '06 #2
Thank you BSOB
I will need to more specific...

Scenario
Form1: Listbox with Patient names (created and works fine).
Form2: Datagridview with complete patient profile, doctor, diagnosis, etc. (created and works fine).

Problem (how do I do this across 2 forms)
When the user selects the patient of interest, Form2 will open and show the profile data for the selected patient.
I can do this easily enough on one form, problem for me is doing this across two forms.
Again, VisualBasic2005, not .net
Thank you in advance, PG
Jul 18 '06 #3
BSOB
77
i read the first post as asking how to OPEN form2.
now i understand...
You need to pass information from one form to another. this is hard because of the scope of any variable that is defined in a form is limited to THAT form. This is why modules exist. in your project tree veiwer (i think upper right hand corner) right click and say add new module.
think for a second, that each of your forms is a person. your group of people is your project. the module is sorta like an umbrella over these people. it is not a form because it has no "face". all it does is provide a function, which is to link the people in your group. it has only code, but no objects or properties. i use the module as central control for all my forms and "stuff".

define a varaible in this module with one line of code:
(note, dont use "dim", use "global")
Global PatientIndex as integer

'then on form1:
listbox1_click()
patientindex = listbox1.listindex
form2.show
unload me
end sub

'on form2:
form_load()
'insert select case or if-then or choose() for patientindex
end sub

it is posible that i havent answered your questions still. try asking one more time if i havent.
Jul 18 '06 #4
That all made sense, thx, however, the Global use here seems incorrect...
In my code window, it highlighted "Global" as syntax error.

Module Module1
Global PatientIndex as integer
End Module

I'm sure I did something wrong, not really used to using modules.
PG
Jul 18 '06 #5
BSOB
77
well. the "global..." is right. im not sure where you got the diea of module module1 and end module...
when you open a new module you get a blank slate. if you dont have a blank slate, delete everything in it. then add the line

global patientindex as string

this line stands alone. no other code. it is sorta a loner.
treat it like the general declaration area of a form.
i hope that is enough, im going away for a few days.
-bsob
Jul 19 '06 #6
Your not sure where I got that? Check the thread.
Anyway, you tried to help me, and in a way, you did, so thank you.
Enjoy your days away, PG
Jul 19 '06 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Miles | last post by:
I have a VB2005 application that has the need to read FoxPro 2.5 DBF/CDX files. I have the code (below) that opens the connection, but there are never any records, nor errors, reported... Can...
5
by: Screaming Eagles 101 | last post by:
Hi , not much trouble in making a setup project, but I'd like also an icon in All Programs to uninstall the application. I can't find a good explanation on the net so far... -- Filip...
8
by: =?Utf-8?B?QWw=?= | last post by:
I am working in vb2005. how can I calculate business days (not including holidays and weekends) between 2 dates? thanks Al
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.