By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,209 Members | 1,100 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,209 IT Pros & Developers. It's quick & easy.

Help Please

P: n/a
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
Nov 15 '05 #1
Share this Question
Share on Google+
23 Replies


P: n/a
bB
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...
"Jason" <no****@hotmail.com> wrote in message
news:uK**************@TK2MSFTNGP11.phx.gbl...
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

Nov 15 '05 #2

P: n/a

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" <no****@hotmail.com>
| 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: <uK**************@TK2MSFTNGP11.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: 64.207.45.37
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP11.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
|
|
|

Nov 15 '05 #3

P: n/a

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" <no****@hotmail.com>
| 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: <uK**************@TK2MSFTNGP11.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: 64.207.45.37
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP11.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
|
|
|

Nov 15 '05 #4

P: n/a
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 informationfrom 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" <no****@hotmail.com>
| 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: <uK**************@TK2MSFTNGP11.phx.gbl>
| 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 onhow
| 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
|
|
|

.

Nov 15 '05 #5

P: n/a
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" <no****@hotmail.com>
| 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: <uK**************@TK2MSFTNGP11.phx.gbl>
| 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

Nov 15 '05 #6

P: n/a
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" <girishb@nowhere> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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" <no****@hotmail.com>
| 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: <uK**************@TK2MSFTNGP11.phx.gbl>
| 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

Nov 15 '05 #7

P: n/a
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" <no****@hotmail.com> wrote in message
news:%2******************@TK2MSFTNGP12.phx.gbl...
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/>
Nov 15 '05 #8

P: n/a

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" <no****@hotmail.com>
| References: <uK**************@TK2MSFTNGP11.phx.gbl>
<TA**************@cpmsftngxa06.phx.gbl>
<01****************************@phx.gbl>
<#G**************@tk2msftngp13.phx.gbl>
| 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: <#U**************@TK2MSFTNGP12.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: 64.207.45.37
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP12.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
|
| "Girish Bharadwaj" <girishb@nowhere> wrote in message
| news:%2****************@tk2msftngp13.phx.gbl...
| > 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" <no****@hotmail.com>
| > >>| 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: <uK**************@TK2MSFTNGP11.phx.gbl>
| > >>| 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
| >
|
|
|

Nov 15 '05 #9

P: n/a
Dan
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]"" <v-*****@online.microsoft.com> wrote in message
news:B7**************@cpmsftngxa06.phx.gbl...

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" <no****@hotmail.com>
| References: <uK**************@TK2MSFTNGP11.phx.gbl>
<TA**************@cpmsftngxa06.phx.gbl>
<01****************************@phx.gbl>
<#G**************@tk2msftngp13.phx.gbl>
| 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: <#U**************@TK2MSFTNGP12.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: 64.207.45.37
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP12.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
|
| "Girish Bharadwaj" <girishb@nowhere> wrote in message
| news:%2****************@tk2msftngp13.phx.gbl...
| > 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" <no****@hotmail.com>
| > >>| 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: <uK**************@TK2MSFTNGP11.phx.gbl>
| > >>| 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
| >
|
|
|

Nov 15 '05 #10

P: n/a

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" <no****@hotmail.com>
| References: <uK**************@TK2MSFTNGP11.phx.gbl>
<TA**************@cpmsftngxa06.phx.gbl>
<01****************************@phx.gbl>
<#G**************@tk2msftngp13.phx.gbl>
<#U**************@TK2MSFTNGP12.phx.gbl>
<B7**************@cpmsftngxa06.phx.gbl>
| 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: <eB**************@tk2msftngp13.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: 64.207.45.37
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftn gp13.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
|
| ""Jeffrey Tan[MSFT]"" <v-*****@online.microsoft.com> wrote in message
| news:B7**************@cpmsftngxa06.phx.gbl...
| >
| > 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" <no****@hotmail.com>
| > | References: <uK**************@TK2MSFTNGP11.phx.gbl>
| > <TA**************@cpmsftngxa06.phx.gbl>
| > <01****************************@phx.gbl>
| > <#G**************@tk2msftngp13.phx.gbl>
| > | 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: <#U**************@TK2MSFTNGP12.phx.gbl>
| > | Newsgroups: microsoft.public.dotnet.languages.csharp
| > | NNTP-Posting-Host: 64.207.45.37
| > | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP12.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
| > |
| > | "Girish Bharadwaj" <girishb@nowhere> wrote in message
| > | news:%2****************@tk2msftngp13.phx.gbl...
| > | > 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" <no****@hotmail.com>
| > | > >>| 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: <uK**************@TK2MSFTNGP11.phx.gbl>
| > | > >>| 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
| > | >
| > |
| > |
| > |
| >
|
|
|

Nov 15 '05 #11

P: n/a
Dan
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]"" <v-*****@online.microsoft.com> wrote in message
news:ns**************@cpmsftngxa06.phx.gbl...

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" <no****@hotmail.com>
| References: <uK**************@TK2MSFTNGP11.phx.gbl>
<TA**************@cpmsftngxa06.phx.gbl>
<01****************************@phx.gbl>
<#G**************@tk2msftngp13.phx.gbl>
<#U**************@TK2MSFTNGP12.phx.gbl>
<B7**************@cpmsftngxa06.phx.gbl>
| 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: <eB**************@tk2msftngp13.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: 64.207.45.37
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftn gp13.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
|
| ""Jeffrey Tan[MSFT]"" <v-*****@online.microsoft.com> wrote in message
| news:B7**************@cpmsftngxa06.phx.gbl...
| >
| > 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" <no****@hotmail.com>
| > | References: <uK**************@TK2MSFTNGP11.phx.gbl>
| > <TA**************@cpmsftngxa06.phx.gbl>
| > <01****************************@phx.gbl>
| > <#G**************@tk2msftngp13.phx.gbl>
| > | 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: <#U**************@TK2MSFTNGP12.phx.gbl>
| > | Newsgroups: microsoft.public.dotnet.languages.csharp
| > | NNTP-Posting-Host: 64.207.45.37
| > | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP12.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
| > |
| > | "Girish Bharadwaj" <girishb@nowhere> wrote in message
| > | news:%2****************@tk2msftngp13.phx.gbl...
| > | > 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" <no****@hotmail.com>
| > | > >>| 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: <uK**************@TK2MSFTNGP11.phx.gbl>
| > | > >>| 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
| > | >
| > |
| > |
| > |
| >
|
|
|

Nov 15 '05 #12

P: n/a
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

Nov 15 '05 #13

P: n/a
Dan
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
"Girish Bharadwaj" <girishb@nowhere> wrote in message
news:eH**************@TK2MSFTNGP09.phx.gbl...
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

Nov 15 '05 #14

P: n/a

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),thi s,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" <sp**@hotmail.com>
| References: <uK**************@TK2MSFTNGP11.phx.gbl>
<TA**************@cpmsftngxa06.phx.gbl>
<01****************************@phx.gbl>
<#G**************@tk2msftngp13.phx.gbl>
<#U**************@TK2MSFTNGP12.phx.gbl>
<B7**************@cpmsftngxa06.phx.gbl>
<eB**************@tk2msftngp13.phx.gbl>
<ns**************@cpmsftngxa06.phx.gbl>
<#0**************@TK2MSFTNGP10.phx.gbl>
<eH**************@TK2MSFTNGP09.phx.gbl>
| 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: <u4**************@TK2MSFTNGP12.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: 64.207.45.37
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP12.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
|
|
| "Girish Bharadwaj" <girishb@nowhere> wrote in message
| news:eH**************@TK2MSFTNGP09.phx.gbl...
| > 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
| >
|
|
|

Nov 15 '05 #15

P: n/a

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" <sp**@hotmail.com>
| References: <uK**************@TK2MSFTNGP11.phx.gbl>
<TA**************@cpmsftngxa06.phx.gbl>
<01****************************@phx.gbl>
<#G**************@tk2msftngp13.phx.gbl>
<#U**************@TK2MSFTNGP12.phx.gbl>
<B7**************@cpmsftngxa06.phx.gbl>
<eB**************@tk2msftngp13.phx.gbl>
<ns**************@cpmsftngxa06.phx.gbl>
<#0**************@TK2MSFTNGP10.phx.gbl>
<eH**************@TK2MSFTNGP09.phx.gbl>
| 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: <u4**************@TK2MSFTNGP12.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: 64.207.45.37
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP12.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
|
|
| "Girish Bharadwaj" <girishb@nowhere> wrote in message
| news:eH**************@TK2MSFTNGP09.phx.gbl...
| > 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
| >
|
|
|

Nov 15 '05 #16

P: n/a
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]"" <v-*****@online.microsoft.com> wrote in message
news:AO**************@cpmsftngxa06.phx.gbl...

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" <sp**@hotmail.com>
| References: <uK**************@TK2MSFTNGP11.phx.gbl>
<TA**************@cpmsftngxa06.phx.gbl>
<01****************************@phx.gbl>
<#G**************@tk2msftngp13.phx.gbl>
<#U**************@TK2MSFTNGP12.phx.gbl>
<B7**************@cpmsftngxa06.phx.gbl>
<eB**************@tk2msftngp13.phx.gbl>
<ns**************@cpmsftngxa06.phx.gbl>
<#0**************@TK2MSFTNGP10.phx.gbl>
<eH**************@TK2MSFTNGP09.phx.gbl>
| 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: <u4**************@TK2MSFTNGP12.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: 64.207.45.37
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP12.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
|
|
| "Girish Bharadwaj" <girishb@nowhere> wrote in message
| news:eH**************@TK2MSFTNGP09.phx.gbl...
| > 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
| >
|
|
|

Nov 15 '05 #17

P: n/a
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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #18

P: n/a
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

"keyur shah" <ke***@softwareklinic.com> wrote in message
news:eX**************@TK2MSFTNGP09.phx.gbl...
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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 15 '05 #19

P: n/a

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" <sp**@hotmail.com>
| References: <uK**************@TK2MSFTNGP11.phx.gbl>
<TA**************@cpmsftngxa06.phx.gbl>
<01****************************@phx.gbl>
<#G**************@tk2msftngp13.phx.gbl>
<#U**************@TK2MSFTNGP12.phx.gbl>
<B7**************@cpmsftngxa06.phx.gbl>
<eB**************@tk2msftngp13.phx.gbl>
<ns**************@cpmsftngxa06.phx.gbl>
<#0**************@TK2MSFTNGP10.phx.gbl>
<eH**************@TK2MSFTNGP09.phx.gbl>
<u4**************@TK2MSFTNGP12.phx.gbl>
<AO**************@cpmsftngxa06.phx.gbl>
| 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: <uv**************@TK2MSFTNGP09.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: 64.207.45.37
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP09.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
|
| ""Jeffrey Tan[MSFT]"" <v-*****@online.microsoft.com> wrote in message
| news:AO**************@cpmsftngxa06.phx.gbl...
| >
| > 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" <sp**@hotmail.com>
| > | References: <uK**************@TK2MSFTNGP11.phx.gbl>
| > <TA**************@cpmsftngxa06.phx.gbl>
| > <01****************************@phx.gbl>
| > <#G**************@tk2msftngp13.phx.gbl>
| > <#U**************@TK2MSFTNGP12.phx.gbl>
| > <B7**************@cpmsftngxa06.phx.gbl>
| > <eB**************@tk2msftngp13.phx.gbl>
| > <ns**************@cpmsftngxa06.phx.gbl>
| > <#0**************@TK2MSFTNGP10.phx.gbl>
| > <eH**************@TK2MSFTNGP09.phx.gbl>
| > | 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: <u4**************@TK2MSFTNGP12.phx.gbl>
| > | Newsgroups: microsoft.public.dotnet.languages.csharp
| > | NNTP-Posting-Host: 64.207.45.37
| > | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP12.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
| > |
| > |
| > | "Girish Bharadwaj" <girishb@nowhere> wrote in message
| > | news:eH**************@TK2MSFTNGP09.phx.gbl...
| > | > 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
| > | >
| > |
| > |
| > |
| >
|
|
|

Nov 15 '05 #20

P: n/a
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]"" <v-*****@online.microsoft.com> wrote in message
news:vw**************@cpmsftngxa06.phx.gbl...

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" <sp**@hotmail.com>
| References: <uK**************@TK2MSFTNGP11.phx.gbl>
<TA**************@cpmsftngxa06.phx.gbl>
<01****************************@phx.gbl>
<#G**************@tk2msftngp13.phx.gbl>
<#U**************@TK2MSFTNGP12.phx.gbl>
<B7**************@cpmsftngxa06.phx.gbl>
<eB**************@tk2msftngp13.phx.gbl>
<ns**************@cpmsftngxa06.phx.gbl>
<#0**************@TK2MSFTNGP10.phx.gbl>
<eH**************@TK2MSFTNGP09.phx.gbl>
<u4**************@TK2MSFTNGP12.phx.gbl>
<AO**************@cpmsftngxa06.phx.gbl>
| 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: <uv**************@TK2MSFTNGP09.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: 64.207.45.37
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP09.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
|
| ""Jeffrey Tan[MSFT]"" <v-*****@online.microsoft.com> wrote in message
| news:AO**************@cpmsftngxa06.phx.gbl...
| >
| > 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" <sp**@hotmail.com>
| > | References: <uK**************@TK2MSFTNGP11.phx.gbl>
| > <TA**************@cpmsftngxa06.phx.gbl>
| > <01****************************@phx.gbl>
| > <#G**************@tk2msftngp13.phx.gbl>
| > <#U**************@TK2MSFTNGP12.phx.gbl>
| > <B7**************@cpmsftngxa06.phx.gbl>
| > <eB**************@tk2msftngp13.phx.gbl>
| > <ns**************@cpmsftngxa06.phx.gbl>
| > <#0**************@TK2MSFTNGP10.phx.gbl>
| > <eH**************@TK2MSFTNGP09.phx.gbl>
| > | 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: <u4**************@TK2MSFTNGP12.phx.gbl>
| > | Newsgroups: microsoft.public.dotnet.languages.csharp
| > | NNTP-Posting-Host: 64.207.45.37
| > | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP12.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
| > |
| > |
| > | "Girish Bharadwaj" <girishb@nowhere> wrote in message
| > | news:eH**************@TK2MSFTNGP09.phx.gbl...
| > | > 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
| > | >
| > |
| > |
| > |
| >
|
|
|

Nov 15 '05 #21

P: n/a

Hi Jason,

Sorry, I still can not reproduce your problem, here is my sample code:

private void button1_Click(object sender, System.EventArgs e)
{
Assembly assem = Assembly.GetAssembly(typeof(Form));
Type t = assem.GetType("System.Windows.Forms.TextBox");
object obj = Activator.CreateInstance(t);
Control tb = (Control)obj;
this.Controls.Add(tb);
tb.Font = this.Font;
this.optionsGroupBox.Controls.Add(tb);
tb.Name = "dynamictextbox";
object tag=(object)"textboxtag";
tb.Tag = tag;
if (tb.GetType() == typeof(TextBox))
{
TextBox tbox = (TextBox)tb;
tbox.Text = "textboxtag";
}
}

private void button2_Click(object sender, System.EventArgs e)
{
foreach(Control c in optionsGroupBox.Controls)
{
MessageBox.Show(c.Tag.ToString());
}
}

I have set the control's tag property and show it up. It works well on my
machine.
I think you can try this code on your machine.

If I misunderstand you, 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: "Jason" <sp**@hotmail.com>
| References: <uK**************@TK2MSFTNGP11.phx.gbl>
<TA**************@cpmsftngxa06.phx.gbl>
<01****************************@phx.gbl>
<#G**************@tk2msftngp13.phx.gbl>
<#U**************@TK2MSFTNGP12.phx.gbl>
<B7**************@cpmsftngxa06.phx.gbl>
<eB**************@tk2msftngp13.phx.gbl>
<ns**************@cpmsftngxa06.phx.gbl>
<#0**************@TK2MSFTNGP10.phx.gbl>
<eH**************@TK2MSFTNGP09.phx.gbl>
<u4**************@TK2MSFTNGP12.phx.gbl>
<AO**************@cpmsftngxa06.phx.gbl>
<uv**************@TK2MSFTNGP09.phx.gbl>
<vw**************@cpmsftngxa06.phx.gbl>
| Subject: Re: Help Please
| Date: Wed, 5 Nov 2003 09:05:15 -0700
| Lines: 249
| 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: <uD**************@TK2MSFTNGP10.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: 64.207.45.37
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP10.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:196957
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| 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]"" <v-*****@online.microsoft.com> wrote in message
| news:vw**************@cpmsftngxa06.phx.gbl...
| >
| > 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" <sp**@hotmail.com>
| > | References: <uK**************@TK2MSFTNGP11.phx.gbl>
| > <TA**************@cpmsftngxa06.phx.gbl>
| > <01****************************@phx.gbl>
| > <#G**************@tk2msftngp13.phx.gbl>
| > <#U**************@TK2MSFTNGP12.phx.gbl>
| > <B7**************@cpmsftngxa06.phx.gbl>
| > <eB**************@tk2msftngp13.phx.gbl>
| > <ns**************@cpmsftngxa06.phx.gbl>
| > <#0**************@TK2MSFTNGP10.phx.gbl>
| > <eH**************@TK2MSFTNGP09.phx.gbl>
| > <u4**************@TK2MSFTNGP12.phx.gbl>
| > <AO**************@cpmsftngxa06.phx.gbl>
| > | 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: <uv**************@TK2MSFTNGP09.phx.gbl>
| > | Newsgroups: microsoft.public.dotnet.languages.csharp
| > | NNTP-Posting-Host: 64.207.45.37
| > | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP09.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
| > |
| > | ""Jeffrey Tan[MSFT]"" <v-*****@online.microsoft.com> wrote in message
| > | news:AO**************@cpmsftngxa06.phx.gbl...
| > | >
| > | > 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" <sp**@hotmail.com>
| > | > | References: <uK**************@TK2MSFTNGP11.phx.gbl>
| > | > <TA**************@cpmsftngxa06.phx.gbl>
| > | > <01****************************@phx.gbl>
| > | > <#G**************@tk2msftngp13.phx.gbl>
| > | > <#U**************@TK2MSFTNGP12.phx.gbl>
| > | > <B7**************@cpmsftngxa06.phx.gbl>
| > | > <eB**************@tk2msftngp13.phx.gbl>
| > | > <ns**************@cpmsftngxa06.phx.gbl>
| > | > <#0**************@TK2MSFTNGP10.phx.gbl>
| > | > <eH**************@TK2MSFTNGP09.phx.gbl>
| > | > | 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: <u4**************@TK2MSFTNGP12.phx.gbl>
| > | > | Newsgroups: microsoft.public.dotnet.languages.csharp
| > | > | NNTP-Posting-Host: 64.207.45.37
| > | > | Path:
cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP12.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
| > | > |
| > | > |
| > | > | "Girish Bharadwaj" <girishb@nowhere> wrote in message
| > | > | news:eH**************@TK2MSFTNGP09.phx.gbl...
| > | > | > 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
| > | > | >
| > | > |
| > | > |
| > | > |
| > | >
| > |
| > |
| > |
| >
|
|
|

Nov 15 '05 #22

P: n/a
Jason,

Thanks for your help. The problem was when I was trying to loop through
each control in the groupbox and removing them at the same time if the tag
value was not correct. Was not using a counter to remove each item I was
using the foreach loop.

Thanks again

""Jeffrey Tan[MSFT]"" <v-*****@online.microsoft.com> wrote in message
news:i$*************@cpmsftngxa06.phx.gbl...

Hi Jason,

Sorry, I still can not reproduce your problem, here is my sample code:

private void button1_Click(object sender, System.EventArgs e)
{
Assembly assem = Assembly.GetAssembly(typeof(Form));
Type t = assem.GetType("System.Windows.Forms.TextBox");
object obj = Activator.CreateInstance(t);
Control tb = (Control)obj;
this.Controls.Add(tb);
tb.Font = this.Font;
this.optionsGroupBox.Controls.Add(tb);
tb.Name = "dynamictextbox";
object tag=(object)"textboxtag";
tb.Tag = tag;
if (tb.GetType() == typeof(TextBox))
{
TextBox tbox = (TextBox)tb;
tbox.Text = "textboxtag";
}
}

private void button2_Click(object sender, System.EventArgs e)
{
foreach(Control c in optionsGroupBox.Controls)
{
MessageBox.Show(c.Tag.ToString());
}
}

I have set the control's tag property and show it up. It works well on my
machine.
I think you can try this code on your machine.

If I misunderstand you, 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: "Jason" <sp**@hotmail.com>
| References: <uK**************@TK2MSFTNGP11.phx.gbl>
<TA**************@cpmsftngxa06.phx.gbl>
<01****************************@phx.gbl>
<#G**************@tk2msftngp13.phx.gbl>
<#U**************@TK2MSFTNGP12.phx.gbl>
<B7**************@cpmsftngxa06.phx.gbl>
<eB**************@tk2msftngp13.phx.gbl>
<ns**************@cpmsftngxa06.phx.gbl>
<#0**************@TK2MSFTNGP10.phx.gbl>
<eH**************@TK2MSFTNGP09.phx.gbl>
<u4**************@TK2MSFTNGP12.phx.gbl>
<AO**************@cpmsftngxa06.phx.gbl>
<uv**************@TK2MSFTNGP09.phx.gbl>
<vw**************@cpmsftngxa06.phx.gbl>
| Subject: Re: Help Please
| Date: Wed, 5 Nov 2003 09:05:15 -0700
| Lines: 249
| 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: <uD**************@TK2MSFTNGP10.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: 64.207.45.37
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP10.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:196957 | X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| 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]"" <v-*****@online.microsoft.com> wrote in message
| news:vw**************@cpmsftngxa06.phx.gbl...
| >
| > 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" <sp**@hotmail.com>
| > | References: <uK**************@TK2MSFTNGP11.phx.gbl>
| > <TA**************@cpmsftngxa06.phx.gbl>
| > <01****************************@phx.gbl>
| > <#G**************@tk2msftngp13.phx.gbl>
| > <#U**************@TK2MSFTNGP12.phx.gbl>
| > <B7**************@cpmsftngxa06.phx.gbl>
| > <eB**************@tk2msftngp13.phx.gbl>
| > <ns**************@cpmsftngxa06.phx.gbl>
| > <#0**************@TK2MSFTNGP10.phx.gbl>
| > <eH**************@TK2MSFTNGP09.phx.gbl>
| > <u4**************@TK2MSFTNGP12.phx.gbl>
| > <AO**************@cpmsftngxa06.phx.gbl>
| > | 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: <uv**************@TK2MSFTNGP09.phx.gbl>
| > | Newsgroups: microsoft.public.dotnet.languages.csharp
| > | NNTP-Posting-Host: 64.207.45.37
| > | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP09.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
| > |
| > | ""Jeffrey Tan[MSFT]"" <v-*****@online.microsoft.com> wrote in message | > | news:AO**************@cpmsftngxa06.phx.gbl...
| > | >
| > | > 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" <sp**@hotmail.com>
| > | > | References: <uK**************@TK2MSFTNGP11.phx.gbl>
| > | > <TA**************@cpmsftngxa06.phx.gbl>
| > | > <01****************************@phx.gbl>
| > | > <#G**************@tk2msftngp13.phx.gbl>
| > | > <#U**************@TK2MSFTNGP12.phx.gbl>
| > | > <B7**************@cpmsftngxa06.phx.gbl>
| > | > <eB**************@tk2msftngp13.phx.gbl>
| > | > <ns**************@cpmsftngxa06.phx.gbl>
| > | > <#0**************@TK2MSFTNGP10.phx.gbl>
| > | > <eH**************@TK2MSFTNGP09.phx.gbl>
| > | > | 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: <u4**************@TK2MSFTNGP12.phx.gbl>
| > | > | Newsgroups: microsoft.public.dotnet.languages.csharp
| > | > | NNTP-Posting-Host: 64.207.45.37
| > | > | Path:
cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP12.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
| > | > |
| > | > |
| > | > | "Girish Bharadwaj" <girishb@nowhere> wrote in message
| > | > | news:eH**************@TK2MSFTNGP09.phx.gbl...
| > | > | > 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
| > | > | >
| > | > |
| > | > |
| > | > |
| > | >
| > |
| > |
| > |
| >
|
|
|

Nov 15 '05 #23

P: n/a

Hi Eric,

Do you have the same problem as jason?
Sorry, you have the same email address as jason, I almost can not
distinguish you from jason.
As jason said, after creating out the controls in groupbox, he wanted to
loop through these controls and check the tag property which tells us if
this control should be removed. The problem is when referring to the tag
property, null reference exception will generate.(only for textbox etc..)

But as I pasted in last post, I have wrote a sample for this, but can not
reproduce his problem.(I also dynamic create the textbox, and loop through
the groupbox, then refer to the tag property). This sample works well on my
machine, I think you also can try this sample.

Thanks
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: "Eric" <sp**@hotmail.com>
| References: <uK**************@TK2MSFTNGP11.phx.gbl>
<TA**************@cpmsftngxa06.phx.gbl>
<01****************************@phx.gbl>
<#G**************@tk2msftngp13.phx.gbl>
<#U**************@TK2MSFTNGP12.phx.gbl>
<B7**************@cpmsftngxa06.phx.gbl>
<eB**************@tk2msftngp13.phx.gbl>
<ns**************@cpmsftngxa06.phx.gbl>
<#0**************@TK2MSFTNGP10.phx.gbl>
<eH**************@TK2MSFTNGP09.phx.gbl>
<u4**************@TK2MSFTNGP12.phx.gbl>
<AO**************@cpmsftngxa06.phx.gbl>
<uv**************@TK2MSFTNGP09.phx.gbl>
<vw**************@cpmsftngxa06.phx.gbl>
<uD**************@TK2MSFTNGP10.phx.gbl>
<i$*************@cpmsftngxa06.phx.gbl>
| Subject: Re: Help Please
| Date: Thu, 6 Nov 2003 14:48:12 -0700
| Lines: 367
| 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: <uK**************@TK2MSFTNGP10.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: 64.207.45.37
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP10.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:197312
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| Jason,
|
| Thanks for your help. The problem was when I was trying to loop through
| each control in the groupbox and removing them at the same time if the tag
| value was not correct. Was not using a counter to remove each item I was
| using the foreach loop.
|
| Thanks again
|
| ""Jeffrey Tan[MSFT]"" <v-*****@online.microsoft.com> wrote in message
| news:i$*************@cpmsftngxa06.phx.gbl...
| >
| > Hi Jason,
| >
| > Sorry, I still can not reproduce your problem, here is my sample code:
| >
| > private void button1_Click(object sender, System.EventArgs e)
| > {
| > Assembly assem = Assembly.GetAssembly(typeof(Form));
| > Type t = assem.GetType("System.Windows.Forms.TextBox");
| > object obj = Activator.CreateInstance(t);
| > Control tb = (Control)obj;
| > this.Controls.Add(tb);
| > tb.Font = this.Font;
| > this.optionsGroupBox.Controls.Add(tb);
| > tb.Name = "dynamictextbox";
| > object tag=(object)"textboxtag";
| > tb.Tag = tag;
| > if (tb.GetType() == typeof(TextBox))
| > {
| > TextBox tbox = (TextBox)tb;
| > tbox.Text = "textboxtag";
| > }
| > }
| >
| > private void button2_Click(object sender, System.EventArgs e)
| > {
| > foreach(Control c in optionsGroupBox.Controls)
| > {
| > MessageBox.Show(c.Tag.ToString());
| > }
| > }
| >
| > I have set the control's tag property and show it up. It works well on
my
| > machine.
| > I think you can try this code on your machine.
| >
| > If I misunderstand you, 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: "Jason" <sp**@hotmail.com>
| > | References: <uK**************@TK2MSFTNGP11.phx.gbl>
| > <TA**************@cpmsftngxa06.phx.gbl>
| > <01****************************@phx.gbl>
| > <#G**************@tk2msftngp13.phx.gbl>
| > <#U**************@TK2MSFTNGP12.phx.gbl>
| > <B7**************@cpmsftngxa06.phx.gbl>
| > <eB**************@tk2msftngp13.phx.gbl>
| > <ns**************@cpmsftngxa06.phx.gbl>
| > <#0**************@TK2MSFTNGP10.phx.gbl>
| > <eH**************@TK2MSFTNGP09.phx.gbl>
| > <u4**************@TK2MSFTNGP12.phx.gbl>
| > <AO**************@cpmsftngxa06.phx.gbl>
| > <uv**************@TK2MSFTNGP09.phx.gbl>
| > <vw**************@cpmsftngxa06.phx.gbl>
| > | Subject: Re: Help Please
| > | Date: Wed, 5 Nov 2003 09:05:15 -0700
| > | Lines: 249
| > | 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: <uD**************@TK2MSFTNGP10.phx.gbl>
| > | Newsgroups: microsoft.public.dotnet.languages.csharp
| > | NNTP-Posting-Host: 64.207.45.37
| > | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP10.phx.gbl
| > | Xref: cpmsftngxa06.phx.gbl
| microsoft.public.dotnet.languages.csharp:196957
| > | X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
| > |
| > | 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]"" <v-*****@online.microsoft.com> wrote in message
| > | news:vw**************@cpmsftngxa06.phx.gbl...
| > | >
| > | > 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" <sp**@hotmail.com>
| > | > | References: <uK**************@TK2MSFTNGP11.phx.gbl>
| > | > <TA**************@cpmsftngxa06.phx.gbl>
| > | > <01****************************@phx.gbl>
| > | > <#G**************@tk2msftngp13.phx.gbl>
| > | > <#U**************@TK2MSFTNGP12.phx.gbl>
| > | > <B7**************@cpmsftngxa06.phx.gbl>
| > | > <eB**************@tk2msftngp13.phx.gbl>
| > | > <ns**************@cpmsftngxa06.phx.gbl>
| > | > <#0**************@TK2MSFTNGP10.phx.gbl>
| > | > <eH**************@TK2MSFTNGP09.phx.gbl>
| > | > <u4**************@TK2MSFTNGP12.phx.gbl>
| > | > <AO**************@cpmsftngxa06.phx.gbl>
| > | > | 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: <uv**************@TK2MSFTNGP09.phx.gbl>
| > | > | Newsgroups: microsoft.public.dotnet.languages.csharp
| > | > | NNTP-Posting-Host: 64.207.45.37
| > | > | Path:
cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP09.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
| > | > |
| > | > | ""Jeffrey Tan[MSFT]"" <v-*****@online.microsoft.com> wrote in
| message
| > | > | news:AO**************@cpmsftngxa06.phx.gbl...
| > | > | >
| > | > | > 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" <sp**@hotmail.com>
| > | > | > | References: <uK**************@TK2MSFTNGP11.phx.gbl>
| > | > | > <TA**************@cpmsftngxa06.phx.gbl>
| > | > | > <01****************************@phx.gbl>
| > | > | > <#G**************@tk2msftngp13.phx.gbl>
| > | > | > <#U**************@TK2MSFTNGP12.phx.gbl>
| > | > | > <B7**************@cpmsftngxa06.phx.gbl>
| > | > | > <eB**************@tk2msftngp13.phx.gbl>
| > | > | > <ns**************@cpmsftngxa06.phx.gbl>
| > | > | > <#0**************@TK2MSFTNGP10.phx.gbl>
| > | > | > <eH**************@TK2MSFTNGP09.phx.gbl>
| > | > | > | 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: <u4**************@TK2MSFTNGP12.phx.gbl>
| > | > | > | Newsgroups: microsoft.public.dotnet.languages.csharp
| > | > | > | NNTP-Posting-Host: 64.207.45.37
| > | > | > | Path:
| > cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP12.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
| > | > | > |
| > | > | > |
| > | > | > | "Girish Bharadwaj" <girishb@nowhere> wrote in message
| > | > | > | news:eH**************@TK2MSFTNGP09.phx.gbl...
| > | > | > | > 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
| > | > | > | >
| > | > | > |
| > | > | > |
| > | > | > |
| > | > | >
| > | > |
| > | > |
| > | > |
| > | >
| > |
| > |
| > |
| >
|
|
|

Nov 15 '05 #24

This discussion thread is closed

Replies have been disabled for this discussion.