Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

The easiest way is to create a subroutine that takes the ComboBox as a parameter and then modify it from there. For example in the class write...

 

Public Sub AddComboItem(ByVal ComboBox as ComboBox, ByVal Item as String)

  ComboBox.Items.Add(Item)

End Sub

 

Then all you have to do is call the subroutine from Form1 (or from elsewhere within the class).

 

Jamie

  • *Experts*
Posted

You need to have the instance of the form object stored in a variable

which can be passed to the class. At that point you can do

myFormVariable.ComboBox1.Items.Add("This and That")

To set a variable to a form's instance, put the following like on the

Form's constructor or _Load event:

myFormVariable = Me

Posted (edited)

the class is in its own file to make it easier for me to get back to when i need to. the onload thing wont work (i tried it) i tried:

 

        Dim Form1 As Form1
       Form1.ComboBox1.Items.Add("United States(Dollar)")
       Form1.ComboBox1.Items.Add("Canada(Dollar)")

 

note: this is a curency converter.

Edited by hitechoutlaw
Posted

ok maybe i said my question wrong...

 

i want to add an item to a list box by calling it from a class.

 

i.e.: i call the class Class1.Action1

 

in the action i want to add items to a list box.

  • *Experts*
Posted

Didn't you see jjjamie's post?

 

Here's the code:

' Put this in Class1
Public Sub Action1(ByVal ComboBox As ComboBox, ByVal Item As String)
  ComboBox.Items.Add(Item)
End Sub

 

You can leave off Item if you want, if the Class1 object is going to know what to add.

 

-Nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
  • *Experts*
Posted

I assume Class1 is an object created in the form. The form is callign the Action1 method on the instance of Class1. The form certainly knows about the ComboBox and can pass it along to the class.

 

-Ner

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted

ok heres what i got and its in form1 with the combobox:

 

    Class fill
       Public Shared Sub fillUSCAN()
           ComboBox2.Items.Add("United States(Dollar)")
           ComboBox2.Items.Add("Canada(Dollar)")
       End Sub
   End Class

it tells me 'Referance to a non shared member requires an object referance.'

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...