Results 1 to 2 of 2

Thread: Arrays

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2001
    Posts
    30

    Arrays

    I've got a populated listbox on a form, whose items I'd like to access from a second form. I've set up my first form so that it imports the second form, but I still can't seem to access it. Here's the code:

    Imports myApp.frmPrefs

    'Dim temp to use in the for each loop
    Dim temp as String

    'Add items from preferences to the items of the cboPayment

    For Each temp In lstPaymentOptions
    cboPayment.Items.Add(temp)
    Next

    So lstPaymentOptions is a listbox on Form2, and I want to access its members from Form1, and ultimately make it's items the choices in a combo drop down box.

    Any help you folks could offer would be greatly appreciated!!
    Thanks!!
    Reid

  2. #2
    Hyperactive Member Bananafish's Avatar
    Join Date
    Jan 2001
    Posts
    394
    Using the "Imports" statement as you have done just makes available the form class, not the specific form object.

    To achieve what you wish to do you will need to extend the scope of your listbox from form2.

    One way to do this is to set up a Public property that accesses it.

    For example in Form2.

    VB Code:
    1. Public Property ShareListBox() As ListBox
    2.       Get
    3.          ShareListBox = ListBox1
    4.       End Get
    5.       Set(ByVal Value As ListBox)
    6.          ListBox1 = Value
    7.       End Set
    8.    End Property

    Now, assuming form1 has a reference to the form2 object then it can access the listbox via the sharelistbox property.

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