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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ProteusGak
    New Member
    • Jul 2006
    • 9

    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
  • BSOB
    New Member
    • Jul 2006
    • 77

    #2
    PG,

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

    ok... heres how this goes. listbox1.listin dex 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.Select ed(2)= true then...

    this checks the 3rd entry and its check box. (in selected(arguem ent) 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

    Comment

    • ProteusGak
      New Member
      • Jul 2006
      • 9

      #3
      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

      Comment

      • BSOB
        New Member
        • Jul 2006
        • 77

        #4
        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.listin dex
        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.

        Comment

        • ProteusGak
          New Member
          • Jul 2006
          • 9

          #5
          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

          Comment

          • BSOB
            New Member
            • Jul 2006
            • 77

            #6
            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

            Comment

            • ProteusGak
              New Member
              • Jul 2006
              • 9

              #7
              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

              Comment

              Working...