PC Review


Reply
Thread Tools Rate Thread

forms control in a class

 
 
kpg
Guest
Posts: n/a
 
      2nd Apr 2010
Hi all,

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

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
 
Reply With Quote
 
 
 
 
Armin Zingler
Guest
Posts: n/a
 
      2nd Apr 2010
Am 02.04.2010 21:41, schrieb kpg:
> Hi all,
>
> 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



Is there a reason why obj is not declared As Combobox?


> 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?



Have you added a reference to a library containing that namespace and type?
You see the containing assembly at the top of each class' documentation
(System.Windows.Forms.dll in this case).


--
Armin
 
Reply With Quote
 
 
 
 
kpg
Guest
Posts: n/a
 
      2nd Apr 2010
> Have you added a reference to a library containing that namespace and
> type? You see the containing assembly at the top of each class'
> documentation (System.Windows.Forms.dll in this case).


Well, I have now...and that fixed it.

...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
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can it possible redefine class with subclass when inherit base class with sub class? ABC Microsoft C# .NET 4 11th Jan 2006 12:13 AM
error LNK2019: unresolved external symbol "public: static class ATL::CStringT<char,class StrTraitMFC<char,class ATL::ChTraitsCRT<char> > > danip Microsoft VC .NET 0 5th Dec 2005 11:01 AM
Getting a reference to the base class of a base class from an inherited class Edward Forgacs Microsoft C# .NET 1 24th Apr 2004 11:06 AM
Pass an instantiated base class to a new class that inherits the same class -- Possible?? Brad Navarro Microsoft C# .NET 3 9th Jan 2004 02:07 AM
activex ,money tree dialer,RdxE Class,updaate class,YInstStarter Class damaged RUSSELL Windows XP Performance 1 23rd Nov 2003 03:05 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:43 PM.