473,666 Members | 2,392 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Create controls programmaticall y

Good evening all,

I am creating a program with the ability to select an option from a
ComboBox which will then create a secondary list of options in a
CheckedListBox. Previously when I have needed to create multiples of
this type of user option I have simply hard coded three or four set
options for the user. However, I would like to have the option for the
user to have as many options available as they like. In order to do
this I have to either hard code a number of these options (there are
approximately 50 of them), or find some way to dynamically create these
controls depending on the user input.

I have looked on DevelopersDex and the Microsoft Visual Studio .NET 2003
help, but I have been unable to find how to do this.

If anyone has had any experience with creating this type of a program,
or any alternatives that have worked better please let me know.

Yours sincerely,

William Foster

*** Sent via Developersdex http://www.developersdex.com ***
Feb 17 '07 #1
8 3756
On 2007-02-17, William Foster <no****@devdex. comwrote:
Good evening all,

I am creating a program with the ability to select an option from a
ComboBox which will then create a secondary list of options in a
CheckedListBox. Previously when I have needed to create multiples of
this type of user option I have simply hard coded three or four set
options for the user. However, I would like to have the option for the
user to have as many options available as they like. In order to do
this I have to either hard code a number of these options (there are
approximately 50 of them), or find some way to dynamically create these
controls depending on the user input.

I have looked on DevelopersDex and the Microsoft Visual Studio .NET 2003
help, but I have been unable to find how to do this.

If anyone has had any experience with creating this type of a program,
or any alternatives that have worked better please let me know.

Yours sincerely,

William Foster

*** Sent via Developersdex http://www.developersdex.com ***
William...

I'm not quite sure what your asking? You say the select an option from a
ComboBox, and then that populates a secondary CheckedListBox. Why do you need
to dynamically create controls? Or, are you planning to do something like the
optons screen in VS - you select from a treeview on the left, and a different
screen appears on the right?

--
Tom Shelton
Feb 17 '07 #2
Tom,

Thanks for the reply, I probably didn't explain my question very well.

It is for a Reporting Program which I need to crete data limits for.
Bascially, what I want to do is once the user selects one option from
the ComboBox and CheckedListBox another set of ComboBox and CheckListBox
are generated, this process would be repeated as many times as the user
wants.

I know that I can create them all and just hide them from the user until
they are required, but I would prefer not to do this as I would
potentially have to create around 50 of each.

For example: the use selects age from the first combobox, then less than
21 from the CheckedListBox, then another ComboBox is created below the
first, and the user has the option to choose something else etc etc.

Yours sincerely,

William Foster

*** Sent via Developersdex http://www.developersdex.com ***
Feb 18 '07 #3
You can create controls programmaticall y on the fly in VB2005. I would
assume it was the same or similar in VB2003. It's something like this:

Dim txt As TextBox = New TextBox()
myForm.Controls .Add(txt)

Robin S.
----------------------------------------
"William Foster" <no****@devdex. comwrote in message
news:%2******** ********@TK2MSF TNGP04.phx.gbl. ..
Tom,

Thanks for the reply, I probably didn't explain my question very well.

It is for a Reporting Program which I need to crete data limits for.
Bascially, what I want to do is once the user selects one option from
the ComboBox and CheckedListBox another set of ComboBox and CheckListBox
are generated, this process would be repeated as many times as the user
wants.

I know that I can create them all and just hide them from the user until
they are required, but I would prefer not to do this as I would
potentially have to create around 50 of each.

For example: the use selects age from the first combobox, then less than
21 from the CheckedListBox, then another ComboBox is created below the
first, and the user has the option to choose something else etc etc.

Yours sincerely,

William Foster

*** Sent via Developersdex http://www.developersdex.com ***

Feb 18 '07 #4
Robin,

Thanks for the help, that worked just as I needed.

I am going to have to undertake a course in Microsoft Help I think, I
can't believe it is that simple yet I couldn't find it in on either
their online or core help files.

Thanks once again !

Yours sincerely,

William Foster

*** Sent via Developersdex http://www.developersdex.com ***
Feb 18 '07 #5
Robin,

One last question; how do you capture events of the newly created
control; what do you address it as in the programming. Usually you just
select the item and the 'Click' event. But how do you know what the
program has called the control?

Yours sincerely,

William Foster

*** Sent via Developersdex http://www.developersdex.com ***
Feb 18 '07 #6
"William Foster" <no****@devdex. comschrieb
Robin,

One last question; how do you capture events of the newly created
control; what do you address it as in the programming. Usually you
just select the item and the 'Click' event. But how do you know
what the program has called the control?
The name doesn't matter. The "Handles" clause connects the event and the
procedure. If not declared "Withevents ":

http://msdn2.microsoft.com/en-us/lib...94(VS.71).aspx

especially sub topic:
http://msdn2.microsoft.com/en-us/lib...93(VS.71).aspx
Armin

Feb 18 '07 #7
On Feb 18, 5:09 am, William Foster <nos...@devdex. comwrote:
Robin,

One last question; how do you capture events of the newly created
control; what do you address it as in the programming. Usually you just
select the item and the 'Click' event. But how do you know what the
program has called the control?

Yours sincerely,

William Foster

*** Sent via Developersdexht tp://www.developersd ex.com***
One last question; how do you capture events of the newly created
control; what do you address it as in the programming.
Use the AddHandler keyword. ie:

<pseudocode>

' This code adds the button and maps it's click event to a handler
Dim button as New Button()
AddHandler button.Click, AddressOf MyDynamicButton _Click(sender as
Object, e as ClickEventArgs)
me.Controls.Add (button)

' This is the sub that will handle the click event
private sub MyDynamicButton _Click(sender as object, e as
ClickEventArgs)
MessageBox.Show ("Hello World!")
end sub

</pseudocode>

Also, if you're not sure what property values you need to set in order
to get your control the way you want it, here's a simple trick. First
create the control in design mode just like you normally do. Then,
pull up Solution Explorer and be sure that the "Show All" option is
selected and then expand the node for the form/usercontrol/whatever
you just laid out the control on. Then open up the MyForm.Designer .Vb
file and look in the region labeled "Component Generated Code" for the
settings of the control you just created - this is the code that is
generated by the designer. Then you can just copy and paste (and
slighty modify) this code and use it when you create the dynamic
control. This is somewhat overkill for simple controls, but can be a
lifesaver when you start dealing with more complex controls.

I hope all that made sense...

Thanks,

Seth Rowe

Feb 18 '07 #8

Well, *that* explains what your problem is. You're using Microsoft Help?!?!

I opened up my Visual Studio help and typed in "add controls" and got this
link.

http://msdn2.microsoft.com/en-us/lib...67(VS.80).aspx

You have to give it the exact right search criteria. Or use Google.
Frequently, their search capabilities against Microsoft's own content are
better than Microsoft's.

Good luck.
Robin S.
Ts'i mahnu uterna ot twan ot geifur hingts uto.
-----------------------------------------------
"William Foster" <no****@devdex. comwrote in message
news:uH******** ******@TK2MSFTN GP06.phx.gbl...
Robin,

Thanks for the help, that worked just as I needed.

I am going to have to undertake a course in Microsoft Help I think, I
can't believe it is that simple yet I couldn't find it in on either
their online or core help files.

Thanks once again !

Yours sincerely,

William Foster

*** Sent via Developersdex http://www.developersdex.com ***

Feb 18 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
3636
by: Patrick | last post by:
I'm working on a contact management application, and need a hand with one aspect... Here's what I want to create: ------------------------------------ A form split into two parts. There is a datagrid on the left side that lists names and perhaps a couple of other key fields. The user can click on a record in the datagrid, which should automatically pull up details on that record in the various text boxes and other controls on the right...
5
4849
by: Jonah Olsson | last post by:
Hello guys, I have an application which is built upon several user controls. That is, I have a default template (default.aspx) that I load a user control into (using placeholders in the template). Now, the template also contains a placeholder for buttons used by each user control. The current solution needs each user control to create its buttons, like;
4
5028
by: | last post by:
I have a "form field highlight" javascript that I've added to some of my ASP.NET forms using the following syntax: body.Attributes.Add("onClick", "highlight(event);"); body.Attributes.Add("onKeyUp", "highlight(event);"); Some of my forms have a great many text box controls that I want to highlight.. I would much rather that ASP.NET do the work of looping through all text boxes and applying these two attributes.
3
3979
by: JohnR | last post by:
I have a form with a number of text boxes, comboboxes etc. What I would like to do is create an event handler for the "mouseenter" event for each of the controls whereby I display information about the control they just entered (sort of like an extended tooltip). Now, I can certainly create a separate mouseenter event for each control (too much work, and not very clever), but what I would like to do is somehow create one event that would...
0
1316
by: mark.norgate | last post by:
Hi I'm having a problem in adding controls to a page programmatically in response to a button click. Composite user controls added programmatically in the CreateChildControls() method work fine; they maintain their state as expected. Cool and groovy. However, since CreateChildControls() is called before the method that responds to the button click, say AddControl_Click(), for some reason, this control does not maintain its
0
1554
by: Kevin Frey | last post by:
We have a data-centric application where all of the "layout" for each data centric page is to be codified (ie. it is expressed in C# code rather than being expressed declaratively). This codification subsequently produces the required web-controls for a page based on whether the page is eg. in view or update mode, examination of the user's security permissions for certain fields, etc. In VS2003 our "Page Master" (to use the VS2005 term)...
3
2636
by: Ken Fine | last post by:
I'm interested in programmatically manipulating groups of ASP.NET controls by type. Can someone suggest code for the following? Loop through, say, all label controls on a page, and assigning a CssClass to them, or programmatically making the Visible/not Visible. If applied to a containing page, such a function would traverse all user controls statically and dynamically placed on the page, correct? Thanks,
0
941
by: | last post by:
I am wondering the best and easiest ways to use the VS.NETvisual designer with data controls that will will be loaded programmatically. For example, I have two datalist controls, one of which I'm populating from a ArrayList based off of the filesystem, and one which uses a dynamically built XmlDataSource. It is occassionally useful to see the semi-rendered view in the VS.NET designer. The hack I'm doing for now is to have a "junk" XML...
11
2938
by: =?Utf-8?B?UGV0ZXIgSw==?= | last post by:
I am working with Visual Studio or alternately with Expression Web. I need to create about 50 aspx pages with about 1200 thumbnali images, typically arranged in three to four groups per page, having hyperlinks to the corresponding full size images. Can anybody point me to locations in MSDN or elsewhere giving the references to attach, the commands & objects for creating or opening the pages and possibly available classes? I have done...
0
8440
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8352
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8863
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8780
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8636
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5661
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4358
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2765
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1763
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.