forms control in a class

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
0
kpg
4/2/2010 7:41:02 PM
dotnet.languages.vb 830 articles. 0 followers. Follow

2 Replies
965 Views

Similar Articles

[PageSpeed] 18

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
0
Armin
4/2/2010 8:07:01 PM
> 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
0
kpg
4/2/2010 8:37:21 PM
Reply:

Similar Artilces:

Do MFC ActiveX Controls have dual interfaces?
Do MFC ActiveX Controls have dual interfaces? Kurt ...

Master/content pages: prob with passing a control to JS
Hi, my code: .... <script type="text/javascript"> var myfilter = myJSfunction(document.myform.ListBox1); </script> </form> When compiling the web page, because of the master/content, the Listbox1 control gets a different name/id apparantly. So how can I pass my listbox on as an argument of my JS procedure? thx for helping, J "Jokke" <Jokke007007@hotmail.com> wrote in message news:7839C9C3-037F-4550-B5BC-E6BA75D93A99@microsoft.com... > When compiling the web page, because of the master/content, the L...

Lookup Function in user form
I have a combo box (cboitem1) and a text box (txtprice1). I am using the code below to have txtprice1 fill with the corresponding price the worksheet: Private Sub Cboitem1_Change() If cboItem1 <> "" Then txtprice1.Value = Excel.WorksheetFunction.VLookup(cboItem1.Value, Sheets("Pizzas").Range("A1:B65536"), 2, False) End If End Sub It works perfectly when you enter an existing value in cboitem1. However if 'the user' accidently types a letter that is not the first letter of one of the existing items VB debugging pops up with error &qu...

Which Controls to Build a Parent/Child Web Form
Hi there, I'm quite new to asp.net, but know exactly how to do this using classic ASP, but would like some pointers for aspnet2. I've got data being returned from an SP which looks like this: HeaderItem ChildItem A A1 A A2 A A3 B B1 etc I want to display the data like this A - This is the header record A1 A2 A3 B - Header 2 B1 etc. In classic ASP I'd write out my header row html when HeaderItem changes value and then write the Child Rows. As I've on...

class unable to write the memory
Hi I've got a class like this class MyClass{ .... somemethods .... protected: int a; } MyClass::MyClass(){ a = 1; } I call the class constructor in the Doc constructor, like I always do, but this time the constructor is unable to modify the memory With the step by step debug I see the 'a' var set to random value as usual, when the compiler runs the 'a=1;' instruciont, the a variable mantains its random value. How is this possible? > I call the class constructor in the Doc constructor, Are you explicitly calling the constructor or it is being called because...

addressing envelope from data input form
I don't know where to start to try this. I have the following fields that make up the entire address: Fname Lname Fname2 Lname 2 Address City, State Zip Is there any way to "push a button" on a form and have it print an envelope for that record? Thanks in advance for any help. -- Posted via a free Usenet account from http://www.teranews.com Have you thought of using an MS template as a starting point? http://office.microsoft.com/en-us/templates/CT101172481033.aspx Dave Eliot wrote: >I don't know where to start to try this. > >I have the following fields ...

Viewing xml created in .Net in a ASP form VB6
I have been trying to create an xml document in VB.Net for displaying on an existing page written in ASP. im having a type mismatch error in my code. When i view my XML i have the following included in the <binary> node. <Binary xmlns:dt="urn:schemas-microsoft-com:datatypes" dt:dt="bin.base64">DATA HERE </Binary My issue is how do i set the datatype of the the node using dotnet so that i can replicate the same node structure and use my existing ASP page. thanks in advance Colin Graham ...

Runtime Control Addition
Hello everybody, I was searching the net for any resource that helps me on the subject of Adding Controls at runtime into a MFC application. I also wanted to handle the messages as well. Please help me on the subject with any tips or resources you know. Thank you so much. Shervin Hello Shervin, > Hello everybody, > > I was searching the net for any resource that helps me on the subject > of > Adding Controls at runtime into a MFC application. I also wanted to > handle > the messages as well. > Please help me on the subject with any tips or resources you know. >...

Creating a form or template
We scanned in an image of a post it note that has graphics on it. It is a jpg file. Can we somehow make this jpg file a form or template in Outlook? Ideally, we want to pull up a form that looks like the image of a post it note with the graphics in tact and be able to compose a message on the email post it note. How do you accomplish this? Thanks! ...

Button Control Event: question
I have a small dialog that prints data it queries from a server to a listbox when a user presses a start button. What I'd like to do is to have the data continually print after the button is pressed until the user presses a stop button. So, I guess I would need to initiate some kind of continuous loop for the data querying/printing, but I'm unsure how to get the stop button to break the loop. If this even the best solution. Does anyone have any ideas of how I could accomplish this, or perhaps a better design idea? Thanks, Marcus Marcus wrote: > I have a small dialog that prints d...

Removing gray shading in protected forms (drop down box)
Hello- I am creating some contract templates for my company's sales force using Word 2003. I am using the forms toolbar to insert checkboxes and drop down boxes from which to select deliverable specifications. The problem is that when a user selects an option from the drop down box, the gray shading remains. I know the sales teams HATE the gray shading because they don't think it looks very good when sending to customers. Is there a way to disable the shading when an option is selected? Thanks. You can remove form field shading altogether using the corresponding b...

Adding BMPs to a form
I use Access 2003. I have a table set up with a field for pictures, this table sits behind a form to add BMPs, which display on the form and print on reports. In the past, when I have had to reinstall Access for any reason, the pictures instead of displaying fully in the form, only show as thumbnails with the file name. I have in the past resoved this by removing Microsoft Picture manager from MS Office. I don't know how I figured that out or why it works but it does. However, I had to reinstall Office yesterday, removed MS Pictrue Manager as usual and it's NOT working ...

Combo values from query based on form fields
I am setting the values for a combo box in a form(s) via a query that 'filters' the results with criteria based upon the values of other fields on the form. The combo is a field that is bound. However, this is giving all kinds of problems ranging from Access completely crashing to being asked for the parameter values of those criteria fields when closing the form. I have tried making the combo an unbound field and then setting the value of the bound field to that unbound field after update, but that still leads to the same issues. How can I do this? As example - I have a form w...

Hyperlink in my Dialog control
I want my text in a dialog control to behave like a hyperlink in a web page. Is it possible and how(VC 6.0) Thanks I. Lesher http://www.codeproject.com/miscctrl/hyperlink.asp Here are some examples: http://www.codeguru.com/staticctrl/HyperlinkStatic.html http://www.codeproject.com/staticctrl/cmyhyperlink.asp http://msdn.microsoft.com/msdnmag/issues/01/01/c/default.aspx (look for CStaticLink) -- Ajay Kalra [MVP - VC++] ajaykalra@yahoo.com "Lesher" <Lesher@triplebit.com> wrote in message news:uRDIoju#DHA.808@TK2MSFTNGP12.phx.gbl... | I want my text in a dialog contr...

cursor control in cells
Can anyone help please? For some reason i am no longer able to scroll across a cell by moving through teh arrow keys. The whole sheet moves instead. Can anyone tell me what I ahve done to lose this control please? Many thanx DAT Hi Dave You have probably inadvertently pressed the Skulk key. Press it again to take Scroll Lock off and you should be OK. -- Regards Roger Govier "Dave T" <datucker@ntlworld.com> wrote in message news:J8sUh.378$V7.132@newsfe7-gui.ntli.net... > Can anyone help please? > For some reason i am no longer able to scroll across a cell by ...

ActiveX vs Forms
Hello- I am trying to embed some option buttons on a worksheet. I want to have two sets of buttons which are mutually exclusive, say A-D and then 1-3. I want to start with 1-3 hidden and if the user chooses option D from the first set then 1-3 will be revealed. I did this fine with the activex option buttons and VBA, however, it is not recognizing A-D and 1-3 as separate groups. Therefore, as soon as the user select 1,2 or 3, it will uncheck D and therefore rehide the remaining numbered boxes. I grouped and named each set of buttons together, but that did not work. If I try to use a group...

Refresh Results In A Second Subform In A Form
Hi, This could be a tricky one. What I've done is created a Form named ACCOUNTS SELECT which has a control being a Comb Box named 'PICK RESNAME' and an embedded subform which returns all the records according to the particular data from the 'PICK RESNAME' Combo Box. Thats all fine and well ! But what I need is to pick specific records and to store them in a let's say temporary Table which I will print out via a Report. For this temporary table, I have created in the Form ACCOUNTS SELECT another Subform which I hoped will view all the selections I have made...

Continuous Form, Window Top Record Ordinal
On continuous view forms, there should be a form property that has the recordset ordinal of the top-most record currently displayed in the form’s window. For example, if a recordset contains 100 records and the CurrentRecord is 5 and the user scrolls down until the CurrentRecord disappears off the top of the screen, what is the recordset ordinal for the record that is now at the top of the window? Left clicking on the scrollbar slider will display “Record: x of y”, but there should be a property that contains the value of x for code purposes. Perhaps call it “WindowTopRecord...

Extra pages in form printing
I have a form that exceeds a single printed page. When it is printed extra pages are produced. The extra pages occur after the first printed page but before the rest of the page of the form is printed and another extra page after the rest of the page is printed. The extra pages contain the same background used in the form. In design view I've made sure to shorten up the background to be even with the footer but it doesn't seem to help. Any suggestion on how to get rid of the extra pages in my printout? Thanks. -- Linda I still do not understand why people print forms. For...

Printing Form 1096
This function should be included in the software! ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If you do not see the button, follow this link to open the suggestion in the Microsoft Web-based Newsreader and then click "I Agree" in the message pane. http://www.microsoft.com/Businesssolutions/Community/NewsGroups/dgbrowser/en-us/default.mspx?mid=20ff4f89-dda7-4896-96f2-6d18c0df63b1&dg=microsoft.public.greatplains T...

Slow Sales Order form
Hi all! Several weeks ago, we successfully transferred our database from SQL Server 2000 to 2005. Below are our steps in transferring the database from 2000 to 2005: a) Backuped our SQL Server 2000 database b) Created an empty database in SQL Server 2005 c) Restored our SQL Server 2000 database to the empty SQL Server 2005 database At first, after the transfer, all functions of the application went very slow. Once I performed the update statistics, the speed of all the functions went back to normal except for some. This is what is causing me headaches right now - these functions th...

Open one form with different queries
Is it possible to open one form using a different query depending on what button the user selects. For example: Sort High/Low Sort Old/New Search MRN Search Account# Search SSN I should also mention that this form has a subform. Got it. Below is what I put behind a button on the form for Sort High/Low and it filters using a query. Dim stHighLow As String stHighLow = "SortHighLow" DoCmd.ApplyFilter stHighLow "Sash" wrote: > Is it possible to open one form using a different query depending on what > button the user selects. For example...

macros on a form
hi we have a workbook containing serveral worksheets each worksheet contains a lot of data we have split each worksheet into three pages for print purposes what we want to do is have a form containing drop down list of names we need each name to select and run a macro can this be done? thanks in advance kevin Kevin Carter Sigma Machining XL and VBA are capable of a lot. From the generic description of the problem, I would say yes. -- Regards, Tushar Mehta www.tushar-mehta.com Business solutions leveraging technology Microsoft Most Valuable Professional (MVP) 2000-2004 In art...

Controls...
Who has controls that can mimic the CRM controls??? http://www.customereffective.com/products_dc.html "Jake Horn" <jhorn@no_order4chaos_spam.com> wrote in message news:O1Yogi2PEHA.2348@TK2MSFTNGP10.phx.gbl... > Who has controls that can mimic the CRM controls??? > > ...

How to create splitter in a CWnd derived class?
Hi, I 've some peculiar problem. I need to create a splitter with two separate views and all inside a CWnd derived class. So I 've to provide splitter control inside a CWnd class and not inside regular CFrameWnd derived classes. Does any body knows how to solve this? Please help me out. Thanks in advance. Snehasish Paul (India) snehasish@gmail.com wrote: > Hi, > > I 've some peculiar problem. > I need to create a splitter with two separate views and all inside a > CWnd derived class. > So I 've to provide splitter control inside a CWnd class and not insi...