|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
forms control in a classI have a vb.net class with this in it: Public Sub SetValues(ByVal obj As Object) DirectCast(obj, ComboBox).Items.Add("Value1") DirectCast(obj, ComboBox).Items.Add("Value2") End Sub Problem: ComboBox is unrecognized becuase this is a class library, not a form. So I add: Imports System.Windows.Forms and I get an error - Warning 1 Namespace or type specified in the Imports 'System.Windows.Forms' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases. Also adding this does not help (of course): DirectCast(obj, System.Windows.Forms.ComboBox).Items.Add("Value1") So how can I have a method that accepts a ComboBox object and manipulates it? Thanks, kpg Am 02.04.2010 21:41, schrieb kpg:
> Hi all, Is there a reason why obj is not declared As Combobox?> > I have a vb.net class with this in it: > > Public Sub SetValues(ByVal obj As Object) > DirectCast(obj, ComboBox).Items.Add("Value1") > DirectCast(obj, ComboBox).Items.Add("Value2") > End Sub Show quoteHide quote > Problem: ComboBox is unrecognized becuase this is a class library, not a Have you added a reference to a library containing that namespace and type?> form. So I add: > > Imports System.Windows.Forms > > and I get an error - > > Warning 1 Namespace or type specified in the Imports > 'System.Windows.Forms' doesn't contain any public member or cannot be > found. Make sure the namespace or the type is defined and contains at least > one public member. Make sure the imported element name doesn't use any > aliases. > > Also adding this does not help (of course): > > DirectCast(obj, System.Windows.Forms.ComboBox).Items.Add("Value1") > > So how can I have a method that accepts a ComboBox object and manipulates > it? You see the containing assembly at the top of each class' documentation (System.Windows.Forms.dll in this case). -- Armin > Have you added a reference to a library containing that namespace and Well, I have now...and that fixed it.> type? You see the containing assembly at the top of each class' > documentation (System.Windows.Forms.dll in this case). ...and there is no reason the obj is not declared as a ComboBox, except I suppose this would work for any control that supports a list, but then it gets cast as a combobox, so no, there is no good reason. thx kpg |
|||||||||||||||||||||||