Results 1 to 4 of 4

Thread: Accessing datagrid on different form

  1. #1

    Thread Starter
    Hyperactive Member Arrow_Raider's Avatar
    Join Date
    Dec 2001
    Location
    AVR Lovers Club
    Posts
    423

    Unhappy Accessing datagrid on different form

    Ok, i got 2 forms, a startup form with a datagrid on it and another form that needs to be able to access the datagrid on the first form. I can't simply call the form like i can in vb6... because i have to access the actual object instance of the form. So i attempted using sub main as my startup item and then having it initialize the main form, however this didn't work. The form would appear and close a second later. I then decided to try making an datagrid object in a module and setting it to the datagrid on the form in the form load event. This didn't work either. It gave the error: "No value at index 0" when i tried accessing the datagrid object from the second form. I just started using visual basic.net.... today...., so i don't know exactly what i am doing.. ahaha. Is there a way to access the startup form from another form? or is there another way i should try doing this?
    My monkey wearing the fedora points and laughs at you.

  2. #2
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    (simplifies problem)
    I have 2 forms:

    Form1 has a datagrid
    Form2 needs to access the datagrid on Form1

    How do i access the datagrid from Form2?

  3. #3
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Put a public property on Form1
    VB Code:
    1. Public Property MyDataSource As DataSet
    2. ...
    3. End Property

    That would give you complete access. You simply share the underlying datasource (whether its a dataset or arraylist).

  4. #4
    Hyperactive Member
    Join Date
    Mar 2004
    Location
    Prato - Tuscany - Italy
    Posts
    461
    Hi Arrow, no panic, surely we can solve that problem!
    I think your way of using sub main is good. You can also pass your object to the second form as a byref (I know, it works also Byval , but it's a question of clear coding) parameter in the constructor (New) procedure. I think you have to post some code.
    Why a form appear and disappear a second later? You have to post your sub main code and the code around where you instance the second form (what happens to the first one? Is it closed or hidden?). I hope I'll be able to help you, if I'll have all informations I need! Bye!
    Live long and prosper (Mr. Spock)

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