Results 1 to 4 of 4

Thread: [2005] URGENT: How to use a variable's value from one form in another??

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2007
    Location
    Singapore
    Posts
    63

    Question [2005] URGENT: How to use a variable's value from one form in another??

    HI Guys!
    I rilli need your help on this one. I have to finish my code and i am stuck pretty bad.

    I have a combobox in one form in my app. i need to use its selectedindex value in another form in the same app. I am not able to do that..

    i tried form1.combobox1.selectedindex but that just returns -1
    and i tried to store its value in a public declared integer variable and use that variable in the second form, this returns 0.

    Please help me out.. i think i might not know exactly how to make a variable declared in one form available in another form.


    thx
    Abhilash

  2. #2
    Fanatic Member
    Join Date
    Feb 2007
    Location
    Eindhoven
    Posts
    828

    Re: [2005] URGENT: How to use a variable's value from one form in another??

    vb Code:
    1. private sub btn1_Click(sender as object, e as eventArgs) handkes btn1.click
    2.   dim frm as new Form2
    3.   frm.textbox1.text = me.comcobox1.selectedIndex
    4.   frm.show
    5. end sub

    or

    in form 2 class

    vb Code:
    1. private index as integer = 0
    2. public sub New(value as integer)
    3.   index = value
    4. end sub
    5.  
    6. private sub form_load()
    7.  me.textbox1.text = value
    8. end sub

    in form 1 class
    vb Code:
    1. private sub btn1_Click(sender as object, e as eventArgs) handkes btn1.click
    2.   dim frm as new Form2(me.combobox1.selectedIndex)
    3.   frm.show
    4. end sub

  3. #3
    Fanatic Member Andy_P's Avatar
    Join Date
    May 2005
    Location
    Dunstable, England
    Posts
    669

    Re: [2005] URGENT: How to use a variable's value from one form in another??

    Using Windows XP Home sp3
    Mucking around with C# 2008 Express
    while ( this.deadHorse ) { flog( ); }


  4. #4

    Thread Starter
    Member
    Join Date
    Mar 2007
    Location
    Singapore
    Posts
    63

    Re: [2005] URGENT: How to use a variable's value from one form in another??

    HI!
    thank you very much for your help talkro and andy.. u been very helpful

    cheers
    Abhilash

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width