473,326 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

create a variable to hold all forms created in a solution

hi all,

im planning to create a lookup usercontrol where i need to specify a
custom property (a form) to be loaded up once a button is pressed.

usercontrol contains:
textbox
button

now how can i create a variable in my usercontrol to list all forms in
my project.

something like:

public <variabletypeListOfFoms;

thanks,

Feb 6 '07 #1
3 1844
If you're just wondering how to get all of the opened Forms you can do that
in the 2.0 Framework with the Application.OpenForms property, which returns
an instance of the FormCollection class (a read-only collection).

If you need to be able to add to a local field an arbitrary number of Forms
created by your UserControl, then you'll probably want a collection that
expands on its own when new Forms are added.

In the 2.0 Framework you can use the generic List<Tclass:

public List<Formforms;

In earlier versions of the Framework, use the ArrayList class instead:

public ArrayList forms;

If you only need a fixed number of Forms then you could use an array of
forms:

public Form[] forms = new Form[10];

although a List<Tor ArrayList would probably be just fine. If you use an
array you'll have to assign the Forms by index, but if you use one of the
list types you'll be able to add them with the Add method.

--
Dave Sexton
http://davesexton.com/blog
http://www.codeplex.com/DocProject (Sandcastle in Visual Studio 2005)

"rGenius" <ru*********@gmail.comwrote in message
news:11*********************@k78g2000cwa.googlegro ups.com...
hi all,

im planning to create a lookup usercontrol where i need to specify a
custom property (a form) to be loaded up once a button is pressed.

usercontrol contains:
textbox
button

now how can i create a variable in my usercontrol to list all forms in
my project.

something like:

public <variabletypeListOfFoms;

thanks,

Feb 6 '07 #2
thanks Dave for a speedy reply,

its what i want, the only thing is how to populate the list with the
list of forms.

i've been trying these to get it done.

List<TypeallForms = new List<Type>();
foreach (Type type in allForms.ToArray())
{
Form curForm =
Assembly.GetEntryAssembly().CreateInstance(type.Fu llName) as Form;
allFormInstance.Add(curForm);
}

thanks,

Feb 6 '07 #3
Hi,

The allForms list is empty, so ToArray will return an empty array. Also,
where and how is allFormInstance defined?

If allForms were to be populated with the Types first, then your loop would
work to iterate over the array correctly. If allFormInstance is something
like, List<Form>, then your code should successfully add instances of each
Form Type in the allForms list to the allFormInstance list as long as each
Form is constructed successfully.

The code could be more succinct:

List<TypeformTypes = new List<Type>();
formTypes.Add(typeof(MyForm));
formTypes.Add(typeof(MyForm2));

// formTypes contains 2 Types: MyForm and MyForm2

List<Formforms = new List<Form>();

foreach (Type type in formTypes)
{
forms.Add(Activator.CreateInstance(type));
}

// forms contains two instances: one of MyForm and one of MyForm2

Just in case, note that the code above isn't useful at all since I
hard-coded typeof(). It could easily have replaced it with a call to the
constructor of each of the two forms:

List<Formforms = new List<Form>();
forms.Add(new MyForm());
forms.Add(new MyForm2());

If you don't know the Types of Forms at design-time then you'll have to use
reflection, as in the previous example.

--
Dave Sexton
http://davesexton.com/blog
http://www.codeplex.com/DocProject (Sandcastle in Visual Studio 2005)

"rGenius" <ru*********@gmail.comwrote in message
news:11**********************@p10g2000cwp.googlegr oups.com...
thanks Dave for a speedy reply,

its what i want, the only thing is how to populate the list with the
list of forms.

i've been trying these to get it done.

List<TypeallForms = new List<Type>();
foreach (Type type in allForms.ToArray())
{
Form curForm =
Assembly.GetEntryAssembly().CreateInstance(type.Fu llName) as Form;
allFormInstance.Add(curForm);
}

thanks,

Feb 6 '07 #4

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

Similar topics

1
by: Not Me | last post by:
Hi, I'm sure this is a common problem.. to create a single field from a whole column, where each row would be separated by a comma. I can do this for a specified table, and column.. and I've...
7
by: Rolf Kemper | last post by:
Dear All, somehow I remember that such or similar question was discussed already somewhere. But I can't find it anymore. I have a template calling itself. As long it goes deeper into the...
2
by: Rudi | last post by:
Is there anyone who can point me to a good tutorial on how to create a multithreaded class library? Class A is a controller that starts up a number of threads of code in Class B. Class B raises...
4
by: DerekM | last post by:
I have a database project that I created with several forms and reports. I would like to be able to declare a single title and be able to change the title on all the forms and reports by changing...
2
by: Remco Groot Beumer | last post by:
Hello, I created a program in which I use modules and classmodules for setting my variables. For example when I need to set the customerID in a variable I use something like: ...
6
by: SamIAm | last post by:
Hi am creating a email application that needs to mail out a very large amount of emails. I have created a multithreaded c# application that using message queuing. I have created a threadpool of 5...
2
by: Bill Nguyen | last post by:
How can I create a shared function to display process progress that can be called from other routines within an application? Any example that I can follow? Thanks Bill
4
by: etuncer | last post by:
Hello All, I have Access 2003, and am trying to build a database for my small company. I want to be able to create a word document based on the data entered through a form. the real question is...
4
by: Alan Mailer | last post by:
Again, I'm new to VB.net and there is something I need help with: Like (I assume) many of us, over time I want to be able to create some VB.net classes that I might want to use in more than one...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.