Hi Dan,
Yes, Just the name of the control type, had better the full name. Such as:
"System.Windows.Forms.TextBox".
Then you can create the control dynamic like this:
System.Reflection.Assembly ass=Assembly.GetAssembly(typeof(Form));
Type t=ass.GetType("System.Windows.Forms.TextBox");
Object obj=Activator.CreateInstance(t);
Control tb=(Control)obj;
this.Controls.Add(tb);
It works well on my machine.
If you still have any question, please feel free to let me know.
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! -
www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
--------------------
| From: "Dan" <
[email protected]>
| References: <
[email protected]>
<
[email protected]>
<
[email protected]>
<#
[email protected]>
<#U6#
[email protected]>
<
[email protected]>
| Subject: Re: Help Please
| Date: Tue, 21 Oct 2003 09:03:27 -0600
| Lines: 201
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <eB07oT#
[email protected]>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: 64.207.45.37
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:192897
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| Thanks for the reply. So, when you state save the type of control - do
you
| mean the string representation of the type of control?
|
| Thanks
|
| | >
| > Hi Mike,
| >
| > Yes, just as girish suggest, you can store the type of the control.
| > When contruct, you can use GetType and Activator.CreateInstance to
dynamic
| > create it.
| >
| > For your groupbox issue, I think you may design a new table which
contains
| > all the controls in the group box, and add a relation between this table
| > and the groupbox control. Then you can contruct the structure of the
form.
| >
| > Hope this helps,
| >
| > Best regards,
| > Jeffrey Tan
| > Microsoft Online Partner Support
| > Get Secure! -
www.microsoft.com/security
| > This posting is provided "as is" with no warranties and confers no
rights.
| >
| > --------------------
| > | From: "Mike" <
[email protected]>
| > | References: <
[email protected]>
| > <
[email protected]>
| > <
[email protected]>
| > <#
[email protected]>
| > | Subject: Re: Help Please
| > | Date: Mon, 20 Oct 2003 15:22:35 -0600
| > | Lines: 143
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| > | X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| > | Message-ID: <#U6#
[email protected]>
| > | Newsgroups: microsoft.public.dotnet.languages.csharp
| > | NNTP-Posting-Host: 64.207.45.37
| > | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
| > | Xref: cpmsftngxa06.phx.gbl
| microsoft.public.dotnet.languages.csharp:192690
| > | X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
| > |
| > | Thanks for the reply, it gives a good start. I have another question
| > | regarding to the meta table and column which describes the type of
| control
| > | to build. I would really like to eliminate in code a huge case
| statement
| > | examining the column string value. Is there a way to get around this?
| > | Also, I have redesigned the app with having a main form with multiple
| > | groupboxes which will be created and shown based on user input. I
would
| > | have thought about serializing the form however with redesign is it
| > possible
| > | to serialize the groupboxes?
| > |
| > | Thanks
| > |
| > | | > | > Jason wrote:
| > | >
| > | > > Thanks for your post. I understand on where to create
| > | > > the controls however I am more interested in on how to
| > | > > use a database to accomplish this. For instance how do I
| > | > > determine the type of control to create and so on.
| > | > >
| > | > > Thanks
| > | > >
| > | > >
| > | > >
| > | > >>-----Original Message-----
| > | > >>
| > | > >>Hi Jason,
| > | > >>
| > | > >>I think you can handle in the Form's Load event.
| > | > >>In this event, you can open the database and retrieve
| > | > >
| > | > > all the information
| > | > >>from the table.
| > | > >
| > | > >>Then you can dynamic construct controls and set their
| > | > >
| > | > > property correctly.
| > | > >
| > | > >>At last, use Form.Controls.Add() method to add them into
| > | > >
| > | > > the form.
| > | > >
| > | > >>If you have any unclear, please feel free to tell me.
| > | > >>
| > | > >>Best regards,
| > | > >>Jeffrey Tan
| > | > >>Microsoft Online Partner Support
| > | > >>Get Secure! -
www.microsoft.com/security
| > | > >>This posting is provided "as is" with no warranties and
| > | > >
| > | > > confers no rights.
| > | > >
| > | > >>--------------------
| > | > >>| From: "Jason" <
[email protected]>
| > | > >>| Subject: Help Please
| > | > >>| Date: Fri, 17 Oct 2003 17:30:56 -0600
| > | > >>| Lines: 10
| > | > >>| X-Priority: 3
| > | > >>| X-MSMail-Priority: Normal
| > | > >>| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| > | > >>| X-MimeOLE: Produced By Microsoft MimeOLE
| > | > >
| > | > > V6.00.2800.1165
| > | > >
| > | > >>| Message-ID: <
[email protected]>
| > | > >>| Newsgroups: microsoft.public.dotnet.languages.csharp
| > | > >>| NNTP-Posting-Host: 64.207.45.37
| > | > >>| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!
| > | > >
| > | > > TK2MSFTNGP11.phx.gbl
| > | > >
| > | > >>| Xref: cpmsftngxa06.phx.gbl
| > | > >
| > | > > microsoft.public.dotnet.languages.csharp:192242
| > | > >
| > | > >>| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
| > | > >>|
| > | > >>| Hi,
| > | > >>|
| > | > >>| I was wondering if any could point me to an example or
| > | > >
| > | > > give me ideas on
| > | > >
| > | > >>how
| > | > >>| to dynamically create a form based on a database
| > | > >
| > | > > table? So, I would have a
| > | > >
| > | > >>| table designed to tell my application to create
| > | > >
| > | > > certain textboxes, labels,
| > | > >
| > | > >>| and combo boxes? Any ideas would be appreciated.
| > | > >>|
| > | > >>| Thanks
| > | > >>|
| > | > >>|
| > | > >>|
| > | > >>
| > | > >>.
| > | > >>
| > | >
| > | >
| > | > A pattern that comes to my mind is as follows. Depending on how easy
| or
| > | > hard you want the solution to be, you can customize this..
| > | >
| > | > 1. You need the actual table that stores data.
| > | > 2. You need a *meta* table that basically describes the UI for that
| > table.
| > | > In order to implement that meta table,
| > | > a, you basically will have one column as the table name,
| > | > b, column name,
| > | > c, display name, [label]
| > | > d, next column would be the type of the data that can be accepted by
| > | > the UI for this,
| > | > e, next couple of columns can indicate the min and max values
| > | > f, if, the column is a foreign key to some other table, the relation
| is
| > | > described in another column. [this will create a combo]. otherwise a
| > | > text box.
| > | >
| > | >
| > | > With this, you can probably develop any UI you want by calling this
| > | > table to figure out the layout. Of course, you can probably figure
out
| > | > most of these by just querying the SQL provider. That is something
you
| > | > can investigate.
| > | >
| > | > Otherwise,
| > | > you might want to look into some sort of serialization mechanism for
| > | > forms [i.e. provide some sort of tags against each control on the UI
| and
| > | > serialize the whole thing to a table and when you are about to
display
| > | > de-serialze that and bring the data back as needed]..
| > | >
| > | > Can you see me waving my hands furiously..

| > | >
| > | > You might want to investigate some of the patterns for this such as
| > | > 1. Factory (for generating UI controls)
| > | > 2. Facade (to wrap this subsystem somewhere)
| > | > 3. ...
| > | >
| > | > --
| > | > Girish Bharadwaj
| > | >
| > |
| > |
| > |
| >
|
|
|