Help Please

  • Thread starter Thread starter Jason
  • Start date Start date
J

Jason

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
 
Object serialization and deserialization would be something to look into.
Serialize your form object and save it as a blob, then when you want to make
an instance of the form, load the blob and then deserialize. Just an
idea...
 
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
|
|
|
 
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
|
|
|
 
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
 
Jason said:
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




all the information


property correctly.


the form.


confers no rights.


give me ideas on


table? So, I would have a


certain textboxes, labels,


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

Girish Bharadwaj said:
Jason said:
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




all the information


property correctly.


the form.


confers no rights.


give me ideas on


table? So, I would have a


certain textboxes, labels,


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. ...
 
One way to do that would be just using the "type" of the control as the
marker.
You should be able to deduce most of the stuff from the datatype / foreign
key relations..
Of course, if you are going to have complicated UI, this might get a little
hairy. i.e. If you have tree structures that you want to represent here.,
that might become hard. But for simple UI, you can probably deduce from the
data type / foreign key ..

Mike said:
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
<snip/>
 
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
| >
|
|
|
 
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

"Jeffrey Tan[MSFT]" said:
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
| >
|
|
|
 
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
| > | >
| > |
| > |
| > |
| >
|
|
|
 
Jeffery,

Your example was very helpful. I do have one more question. How can I add
an event to the control by having the event name in the database. I
understand how to add event to a control however since each control needs a
different method to handle each event. I decided to create in the table a
field to have the event name which I will create the method in design view
and I want to assign it at runtime. The code below gives me an error
(control event does not exist) :

cbo.Click += new EventHandler(controlEvent);

With controlEvent being a string of the method name.

Any ideas how to accomplish this?

Thanks again for all your help.

"Jeffrey Tan[MSFT]" said:
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
| > | >
| > |
| > |
| > |
| >
|
|
|
 
Dan said:
Jeffery,

Your example was very helpful. I do have one more question. How can I add
an event to the control by having the event name in the database. I
understand how to add event to a control however since each control needs a
different method to handle each event. I decided to create in the table a
field to have the event name which I will create the method in design view
and I want to assign it at runtime. The code below gives me an error
(control event does not exist) :

cbo.Click += new EventHandler(controlEvent);

With controlEvent being a string of the method name.

Any ideas how to accomplish this?

Thanks again for all your help.
</snip>
I dont think you want to do that. You might be better off having the
controlEvent be "one" method and within it, you can do the different
things based on a table data. You can probably store C# code or JScript
or some custom language code in the table which you can in turn, using
CodeDOM compiler classes, compile and execute on event..
 
Thanks for the response. For my problem I do not think I need to use
CodeDOM. I rather not make it so complicated that it is hard to maintain.
Saving C# code in the table and then using CodeDOM to run the code at
runtime will make it database driven however isnt there a better way to do
this? I understand I could create one method which I add to each control and
then have a case statement which points to the right method. However, I was
hoping to have methods created at design which would then be called via the
controlEvent name. However, I cannot figure this out. I am looking at the
Invoke method and create a delegate to point to the right method. I could
create a hashtable of delegates mapping to each method. Any other
suggestions would be appreciated. Thanks again for all your help.

Thanks
 
Hi Dan,

I understand your meaning.
You main concern is how to associate the event method with certain event.
I think you should first convert this method string into a delegate object,
then you can add this delegate to the event handler.
Sample code like this:

//the already created event method for textchange event
private void textBox1_TextChanged(object sender, System.EventArgs e)
{
MessageBox.Show("hoho");
}


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);
string eventhandle="textBox1_TextChanged";
Delegate d=Delegate.CreateDelegate(typeof(EventHandler),this,eventhandle);
tb.TextChanged+=(EventHandler)d;

It works well on my machine, if there is anything unclear, 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]>
<eB07oT#[email protected]>
<[email protected]>
<#[email protected]>
<[email protected]>
| Subject: Re: Help Please
| Date: Thu, 23 Oct 2003 15:38:05 -0600
| Lines: 52
| 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!TK2MSFTNGP12.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:193654
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| Thanks for the response. For my problem I do not think I need to use
| CodeDOM. I rather not make it so complicated that it is hard to maintain.
| Saving C# code in the table and then using CodeDOM to run the code at
| runtime will make it database driven however isnt there a better way to do
| this? I understand I could create one method which I add to each control
and
| then have a case statement which points to the right method. However, I
was
| hoping to have methods created at design which would then be called via
the
| controlEvent name. However, I cannot figure this out. I am looking at
the
| Invoke method and create a delegate to point to the right method. I could
| create a hashtable of delegates mapping to each method. Any other
| suggestions would be appreciated. Thanks again for all your help.
|
| Thanks
|
|
| | > Dan wrote:
| > > Jeffery,
| > >
| > > Your example was very helpful. I do have one more question. How can
I
| add
| > > an event to the control by having the event name in the database. I
| > > understand how to add event to a control however since each control
| needs a
| > > different method to handle each event. I decided to create in the
table
| a
| > > field to have the event name which I will create the method in design
| view
| > > and I want to assign it at runtime. The code below gives me an error
| > > (control event does not exist) :
| > >
| > > cbo.Click += new EventHandler(controlEvent);
| > >
| > > With controlEvent being a string of the method name.
| > >
| > > Any ideas how to accomplish this?
| > >
| > > Thanks again for all your help.
| > >
| > </snip>
| > I dont think you want to do that. You might be better off having the
| > controlEvent be "one" method and within it, you can do the different
| > things based on a table data. You can probably store C# code or JScript
| > or some custom language code in the table which you can in turn, using
| > CodeDOM compiler classes, compile and execute on event..
| >
| > --
| > Girish Bharadwaj
| >
|
|
|
 
Hi Dan,

Is your problem resolved?
If you still have any question, 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: "Dan" <[email protected]>
| References: <[email protected]>
<[email protected]>
<[email protected]>
<#[email protected]>
<#U6#[email protected]>
<[email protected]>
<eB07oT#[email protected]>
<[email protected]>
<#[email protected]>
<[email protected]>
| Subject: Re: Help Please
| Date: Thu, 23 Oct 2003 15:38:05 -0600
| Lines: 52
| 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!TK2MSFTNGP12.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:193654
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| Thanks for the response. For my problem I do not think I need to use
| CodeDOM. I rather not make it so complicated that it is hard to maintain.
| Saving C# code in the table and then using CodeDOM to run the code at
| runtime will make it database driven however isnt there a better way to do
| this? I understand I could create one method which I add to each control
and
| then have a case statement which points to the right method. However, I
was
| hoping to have methods created at design which would then be called via
the
| controlEvent name. However, I cannot figure this out. I am looking at
the
| Invoke method and create a delegate to point to the right method. I could
| create a hashtable of delegates mapping to each method. Any other
| suggestions would be appreciated. Thanks again for all your help.
|
| Thanks
|
|
| | > Dan wrote:
| > > Jeffery,
| > >
| > > Your example was very helpful. I do have one more question. How can
I
| add
| > > an event to the control by having the event name in the database. I
| > > understand how to add event to a control however since each control
| needs a
| > > different method to handle each event. I decided to create in the
table
| a
| > > field to have the event name which I will create the method in design
| view
| > > and I want to assign it at runtime. The code below gives me an error
| > > (control event does not exist) :
| > >
| > > cbo.Click += new EventHandler(controlEvent);
| > >
| > > With controlEvent being a string of the method name.
| > >
| > > Any ideas how to accomplish this?
| > >
| > > Thanks again for all your help.
| > >
| > </snip>
| > I dont think you want to do that. You might be better off having the
| > controlEvent be "one" method and within it, you can do the different
| > things based on a table data. You can probably store C# code or JScript
| > or some custom language code in the table which you can in turn, using
| > CodeDOM compiler classes, compile and execute on event..
| >
| > --
| > Girish Bharadwaj
| >
|
|
|
 
Thanks for all your help. Yes, you did help me solve my problem. However,
I am having some problems. The controls are being created correctly and
displaying correctly in a group box. However, I am trying to loop through
each control in the groupbox and looking at each tag. For some reason the
textboxes and comboboxes are undefined controls but the labels are not.
Here is the code I use to create the control:

Assembly assem = Assembly.GetAssembly(typeof(Form));
Type t = assem.GetType(controlType);
object obj = Activator.CreateInstance(t);
Control tb = (Control)obj;
this.Controls.Add(tb);
tb.Font = this.Font;
this.optionsGroupBox.Controls.Add(tb);
tb.Name = controlName;
tb.Tag = tag;
if (tb.GetType() == typeof(Label))
{
Label label = (Label)tb;
label.Text = controlText;
label.TextAlign = ContentAlignment.MiddleLeft;
}
else if(tb.GetType() == typeof(ComboBox))
{
ComboBox cbo = (ComboBox)tb;
cbo.DropDownStyle = ComboBoxStyle.DropDownList;
Delegate d = Delegate.CreateDelegate(typeof(EventHandler), this,
controlEvent);
cbo.Click += (EventHandler)d;
}
tb.SetBounds(locX, locY, sizeX, sizeY);

And I just use a simple foreach(Control ct in this.optionsGroupBox.Controls)
to loop through each control.

Any ideas?

Thanks

"Jeffrey Tan[MSFT]" said:
Hi Dan,

Is your problem resolved?
If you still have any question, 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: "Dan" <[email protected]>
| References: <[email protected]>
<[email protected]>
<[email protected]>
<#[email protected]>
<#U6#[email protected]>
<[email protected]>
<eB07oT#[email protected]>
<[email protected]>
<#[email protected]>
<[email protected]>
| Subject: Re: Help Please
| Date: Thu, 23 Oct 2003 15:38:05 -0600
| Lines: 52
| 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!TK2MSFTNGP12.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:193654
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| Thanks for the response. For my problem I do not think I need to use
| CodeDOM. I rather not make it so complicated that it is hard to maintain.
| Saving C# code in the table and then using CodeDOM to run the code at
| runtime will make it database driven however isnt there a better way to do
| this? I understand I could create one method which I add to each control
and
| then have a case statement which points to the right method. However, I
was
| hoping to have methods created at design which would then be called via
the
| controlEvent name. However, I cannot figure this out. I am looking at
the
| Invoke method and create a delegate to point to the right method. I could
| create a hashtable of delegates mapping to each method. Any other
| suggestions would be appreciated. Thanks again for all your help.
|
| Thanks
|
|
| | > Dan wrote:
| > > Jeffery,
| > >
| > > Your example was very helpful. I do have one more question. How can
I
| add
| > > an event to the control by having the event name in the database. I
| > > understand how to add event to a control however since each control
| needs a
| > > different method to handle each event. I decided to create in the
table
| a
| > > field to have the event name which I will create the method in design
| view
| > > and I want to assign it at runtime. The code below gives me an error
| > > (control event does not exist) :
| > >
| > > cbo.Click += new EventHandler(controlEvent);
| > >
| > > With controlEvent being a string of the method name.
| > >
| > > Any ideas how to accomplish this?
| > >
| > > Thanks again for all your help.
| > >
| > </snip>
| > I dont think you want to do that. You might be better off having the
| > controlEvent be "one" method and within it, you can do the different
| > things based on a table data. You can probably store C# code or JScript
| > or some custom language code in the table which you can in turn, using
| > CodeDOM compiler classes, compile and execute on event..
| >
| > --
| > Girish Bharadwaj
| >
|
|
|
 
You need to develop that logic, for creating the form dynamically.

You need to read the database table schemal... and on basis of type and
size of each field, you can create textbox, combo, radio, checkbox....

Still it would not be that sophisticated. You might want to play around
iwth it...

Or,, what you can do is, u can use data form wizard., to create database
driven forms.,..

Keyur Shah
Verizon Communications
732-423-0745
 
Thanks for the post. I do not know what you are talking about. It works
fine, I read the schema from the database and it creates the controls. The
problem I am having is after I created the controls I want to remove certain
controls based on some user input. So, I loop through each control in the
groupbox that I created and search for certain tag which tells which
controls to remove. In the foreach loop it works fine on the label controls
I created however on the textbox and combobox controls i created are
undefined for some reason. I am trying to understand why this is happening.
If there are created correctly and are shown correctly how can the control
be undefined?

Thanks
 
Thanks for your post. When I loop through the groupbox Controls that I
created some of them are undefined. I get an error based on some of the
controls I created (textboxes and combo boxes and not labels) when I check
the tag value. Here is the error I get:

An unhandled exception of type 'System.NullReferenceException' occurred in
VeraDrill.exe
Additional information: Object reference not set to an instance of an
object.

When I debug I place the cursor over the control when it gets to the combo
box I created and it says ct = undefined value where it should say ct =
System.Windows.Forms.TextBox.

I do not know why this is happening! If the controls are getting created
correctly and showing up on the form why would some of the controls be
undefined?

Thanks

"Jeffrey Tan[MSFT]" said:
Hi Jason,

I am glad your application finally works.
It seems that your new problem related to the tag and loop through the
groupbox.
As you said: "For some reason the textboxes and comboboxes are undefined
controls but the labels are not.", what does undefined mean?
Does this sentence mean that textbox and combobox do not have the tag
property, while the label has the tag?

If I did not misunderstand you, I think you should specify a special value
to tag property for the control that does not have tag property.(Such as 0
or null)
Then, when you loop through the groupbox, you can determine the tag's
value, and use these controls that have the valid tag value.

If I misunderstand you, 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]>
| References: <[email protected]>
<[email protected]>
<[email protected]>
<#[email protected]>
<#U6#[email protected]>
<[email protected]>
<eB07oT#[email protected]>
<[email protected]>
<#[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
| Subject: Re: Help Please
| Date: Tue, 4 Nov 2003 09:54:46 -0700
| Lines: 149
| 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!TK2MSFTNGP09.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:196636
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| Thanks for all your help. Yes, you did help me solve my problem.
However,
| I am having some problems. The controls are being created correctly and
| displaying correctly in a group box. However, I am trying to loop through
| each control in the groupbox and looking at each tag. For some reason the
| textboxes and comboboxes are undefined controls but the labels are not.
| Here is the code I use to create the control:
|
| Assembly assem = Assembly.GetAssembly(typeof(Form));
| Type t = assem.GetType(controlType);
| object obj = Activator.CreateInstance(t);
| Control tb = (Control)obj;
| this.Controls.Add(tb);
| tb.Font = this.Font;
| this.optionsGroupBox.Controls.Add(tb);
| tb.Name = controlName;
| tb.Tag = tag;
| if (tb.GetType() == typeof(Label))
| {
| Label label = (Label)tb;
| label.Text = controlText;
| label.TextAlign = ContentAlignment.MiddleLeft;
| }
| else if(tb.GetType() == typeof(ComboBox))
| {
| ComboBox cbo = (ComboBox)tb;
| cbo.DropDownStyle = ComboBoxStyle.DropDownList;
| Delegate d = Delegate.CreateDelegate(typeof(EventHandler), this,
| controlEvent);
| cbo.Click += (EventHandler)d;
| }
| tb.SetBounds(locX, locY, sizeX, sizeY);
|
| And I just use a simple foreach(Control ct in
this.optionsGroupBox.Controls)
| to loop through each control.
|
| Any ideas?
|
| Thanks
|
| | >
| > Hi Dan,
| >
| > Is your problem resolved?
| > If you still have any question, 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: "Dan" <[email protected]>
| > | References: <[email protected]>
| > <[email protected]>
| > <[email protected]>
| > <#[email protected]>
| > <#U6#[email protected]>
| > <[email protected]>
| > <eB07oT#[email protected]>
| > <[email protected]>
| > <#[email protected]>
| > <[email protected]>
| > | Subject: Re: Help Please
| > | Date: Thu, 23 Oct 2003 15:38:05 -0600
| > | Lines: 52
| > | 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!TK2MSFTNGP12.phx.gbl
| > | Xref: cpmsftngxa06.phx.gbl
| microsoft.public.dotnet.languages.csharp:193654
| > | X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
| > |
| > | Thanks for the response. For my problem I do not think I need to use
| > | CodeDOM. I rather not make it so complicated that it is hard to
| maintain.
| > | Saving C# code in the table and then using CodeDOM to run the code at
| > | runtime will make it database driven however isnt there a better way
to
| do
| > | this? I understand I could create one method which I add to each
control
| > and
| > | then have a case statement which points to the right method.
However, I
| > was
| > | hoping to have methods created at design which would then be called
via
| > the
| > | controlEvent name. However, I cannot figure this out. I am looking
at
| > the
| > | Invoke method and create a delegate to point to the right method. I
| could
| > | create a hashtable of delegates mapping to each method. Any other
| > | suggestions would be appreciated. Thanks again for all your help.
| > |
| > | Thanks
| > |
| > |
| > | | > | > Dan wrote:
| > | > > Jeffery,
| > | > >
| > | > > Your example was very helpful. I do have one more question. How
| can
| > I
| > | add
| > | > > an event to the control by having the event name in the database.
I
| > | > > understand how to add event to a control however since each
control
| > | needs a
| > | > > different method to handle each event. I decided to create in the
| > table
| > | a
| > | > > field to have the event name which I will create the method in
| design
| > | view
| > | > > and I want to assign it at runtime. The code below gives me an
| error
| > | > > (control event does not exist) :
| > | > >
| > | > > cbo.Click += new EventHandler(controlEvent);
| > | > >
| > | > > With controlEvent being a string of the method name.
| > | > >
| > | > > Any ideas how to accomplish this?
| > | > >
| > | > > Thanks again for all your help.
| > | > >
| > | > </snip>
| > | > I dont think you want to do that. You might be better off having the
| > | > controlEvent be "one" method and within it, you can do the different
| > | > things based on a table data. You can probably store C# code or
| JScript
| > | > or some custom language code in the table which you can in turn,
using
| > | > CodeDOM compiler classes, compile and execute on event..
| > | >
| > | > --
| > | > Girish Bharadwaj
| > | >
| > |
| > |
| > |
| >
|
|
|
 
Back
Top