ComboBox Scope Help Needed

  • Thread starter Thread starter bh
  • Start date Start date
B

bh

I'm trying to define a combobox on a form and make it accessible to another
form. I drop the control onto the form in Visual Studio (2003), but when I
go into the code-behind and add the "shared" keyword, the control disappears
from the form. Can comboboxes be shared? What else could be causing this?
Thanks in advance.

bh
 
bh said:
I'm trying to define a combobox on a form and make it accessible to
another form. I drop the control onto the form in Visual Studio (2003),
but when I go into the code-behind and add the "shared" keyword, the
control disappears from the form. Can comboboxes be shared? What else
could be causing this? Thanks in advance.

bh

Shared cannot use class variables which is what the original combobox is.
If you want to access it from elsewhere either create a property (the best
way since you can then debug all access to the control) or make the control
Public.

LS
 
Bh,

You can share them like your wallet.

Give it to somebody else and she will empty it for you.

After that you can get it back to load it again.

(You cannot share it in the same time).

Cor
 
bh said:
I'm trying to define a combobox on a form and make it accessible to another
form.

Not necessarily a good idea - I would expose a Property on the Form that
retrieves and returns the ComboBox's value, for other Forms to use.
I drop the control onto the form in Visual Studio (2003), but when I
go into the code-behind and add the "shared" keyword, the control disappears
from the form.

That's not what "Shared" is for.

Make the ComboBox (or Property) Public (or Friend) and your other Forms
will be able to "see" it.

Shared things are .. well .. shared across all /instances/ of a given
/class/, for example:

Class Bod
Public Shared Function Age() as Integer
Return 21
End Function

Public Sub New(sName as String)
m_sName = sName
End Sub

Public ReadOnly Property Name() as String
Get
Return m_sName
End Get
End Property

Private m_sName as String

End Class

....then...

? Bod.Age
21

Dim b1 as New Bod( "Fred" )
?b1.Name
"Fred"
?b1.Age
21

Dim b2 as New Bod( "Bill" )
?b2.Name
"Bill"
?b1.Age
21

HTH,
Phill W.
 
Back
Top