473,503 Members | 1,818 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

dynamic control creation

i have a user control (say myUserControl) that inherits panel, i create
some textboxes on myUserControl dynamically, then i create some
myUserControls on the form dynamically with a loop . of course i change
name,location etc.. meanwhile.

i have some problems here then.

eg: how could i reach each myUserControl and textBoxes on this
myUserControl.
it could be betterif i reach them directly, i know renaming a control on
the runtime is useless. what should i do?
another issue is, it is not known how many myUserControls on thye from or
textboxes on a myUserControl will be created. i need autoscroll
functionality. on the panel it works, but on the form it seems, autoscroll
does not work.

thnkz


Nov 16 '05 #1
17 1735
e-mid.

There are different ways to do that, i have one recomendation.

1. To reach individual controls, access through properties.

example -

protected TextBox mMyTextBox;

public TexBox MyTextBox
{
get {return mMyTextBox;}
}

2. Autoscroll will work even in design mode of form. I am not sure why
its not working for ur form

Shak.
"e-mid" <someone@somewhere> wrote in message
news:Oi**************@TK2MSFTNGP09.phx.gbl...
i have a user control (say myUserControl) that inherits panel, i create
some textboxes on myUserControl dynamically, then i create some
myUserControls on the form dynamically with a loop . of course i change
name,location etc.. meanwhile.

i have some problems here then.

eg: how could i reach each myUserControl and textBoxes on this
myUserControl.
it could be betterif i reach them directly, i know renaming a control on the runtime is useless. what should i do?
another issue is, it is not known how many myUserControls on thye from or
textboxes on a myUserControl will be created. i need autoscroll
functionality. on the panel it works, but on the form it seems, autoscroll
does not work.

thnkz

Nov 16 '05 #2
e-mid.

There are different ways to do that, i have one recomendation.

1. To reach individual controls, access through properties.

example -

protected TextBox mMyTextBox;

public TexBox MyTextBox
{
get {return mMyTextBox;}
}

2. Autoscroll will work even in design mode of form. I am not sure why
its not working for ur form

Shak.
"e-mid" <someone@somewhere> wrote in message
news:Oi**************@TK2MSFTNGP09.phx.gbl...
i have a user control (say myUserControl) that inherits panel, i create
some textboxes on myUserControl dynamically, then i create some
myUserControls on the form dynamically with a loop . of course i change
name,location etc.. meanwhile.

i have some problems here then.

eg: how could i reach each myUserControl and textBoxes on this
myUserControl.
it could be betterif i reach them directly, i know renaming a control on the runtime is useless. what should i do?
another issue is, it is not known how many myUserControls on thye from or
textboxes on a myUserControl will be created. i need autoscroll
functionality. on the panel it works, but on the form it seems, autoscroll
does not work.

thnkz

Nov 16 '05 #3

"Shakir Hussain" <sh**@fakedomain.com> wrote in message
news:#j**************@tk2msftngp13.phx.gbl...
e-mid.

There are different ways to do that, i have one recomendation.

1. To reach individual controls, access through properties.

example -

protected TextBox mMyTextBox;

public TexBox MyTextBox
{
get {return mMyTextBox;}
i dont think, this way works. controls created dynamically.
another question arised here , is this controls are private by default?
2. Autoscroll will work even in design mode of form. I am not sure why
its not working for ur form
it scrolls horizontally, but vertical autoscroll does not work..

i did not understand why?
Shak.
"e-mid" <someone@somewhere> wrote in message
news:Oi**************@TK2MSFTNGP09.phx.gbl...
i have a user control (say myUserControl) that inherits panel, i create
some textboxes on myUserControl dynamically, then i create some
myUserControls on the form dynamically with a loop . of course i change
name,location etc.. meanwhile.

i have some problems here then.

eg: how could i reach each myUserControl and textBoxes on this
myUserControl.
it could be betterif i reach them directly, i know renaming a control

on
the runtime is useless. what should i do?
another issue is, it is not known how many myUserControls on thye from or textboxes on a myUserControl will be created. i need autoscroll
functionality. on the panel it works, but on the form it seems, autoscroll does not work.

thnkz


Nov 16 '05 #4

"Shakir Hussain" <sh**@fakedomain.com> wrote in message
news:#j**************@tk2msftngp13.phx.gbl...
e-mid.

There are different ways to do that, i have one recomendation.

1. To reach individual controls, access through properties.

example -

protected TextBox mMyTextBox;

public TexBox MyTextBox
{
get {return mMyTextBox;}
i dont think, this way works. controls created dynamically.
another question arised here , is this controls are private by default?
2. Autoscroll will work even in design mode of form. I am not sure why
its not working for ur form
it scrolls horizontally, but vertical autoscroll does not work..

i did not understand why?
Shak.
"e-mid" <someone@somewhere> wrote in message
news:Oi**************@TK2MSFTNGP09.phx.gbl...
i have a user control (say myUserControl) that inherits panel, i create
some textboxes on myUserControl dynamically, then i create some
myUserControls on the form dynamically with a loop . of course i change
name,location etc.. meanwhile.

i have some problems here then.

eg: how could i reach each myUserControl and textBoxes on this
myUserControl.
it could be betterif i reach them directly, i know renaming a control

on
the runtime is useless. what should i do?
another issue is, it is not known how many myUserControls on thye from or textboxes on a myUserControl will be created. i need autoscroll
functionality. on the panel it works, but on the form it seems, autoscroll does not work.

thnkz


Nov 16 '05 #5
* "e-mid" <someone@somewhere> scripsit:
i have a user control (say myUserControl) that inherits panel, i create
some textboxes on myUserControl dynamically, then i create some
myUserControls on the form dynamically with a loop . of course i change
name,location etc.. meanwhile.

i have some problems here then.

eg: how could i reach each myUserControl and textBoxes on this
myUserControl.
it could be betterif i reach them directly, i know renaming a control on
the runtime is useless. what should i do?
\\\
DirectCast(Me.UserControl1.Controls(12), TextBox).Select(2, 10)
///
another issue is, it is not known how many myUserControls on thye from or
textboxes on a myUserControl will be created. i need autoscroll
functionality. on the panel it works, but on the form it seems, autoscroll
does not work.


Mhm... It should work...

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 16 '05 #6
* "e-mid" <someone@somewhere> scripsit:
i have a user control (say myUserControl) that inherits panel, i create
some textboxes on myUserControl dynamically, then i create some
myUserControls on the form dynamically with a loop . of course i change
name,location etc.. meanwhile.

i have some problems here then.

eg: how could i reach each myUserControl and textBoxes on this
myUserControl.
it could be betterif i reach them directly, i know renaming a control on
the runtime is useless. what should i do?
\\\
DirectCast(Me.UserControl1.Controls(12), TextBox).Select(2, 10)
///
another issue is, it is not known how many myUserControls on thye from or
textboxes on a myUserControl will be created. i need autoscroll
functionality. on the panel it works, but on the form it seems, autoscroll
does not work.


Mhm... It should work...

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 16 '05 #7
Herfried, can you explain about this?

DirectCast(Me.UserControl1.Controls(12), TextBox).Select(2, 10)

and i hear about directCast first time, can you point some sources about it?

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:2k*************@uni-berlin.de...
* "e-mid" <someone@somewhere> scripsit:
i have a user control (say myUserControl) that inherits panel, i create
some textboxes on myUserControl dynamically, then i create some
myUserControls on the form dynamically with a loop . of course i change
name,location etc.. meanwhile.

i have some problems here then.

eg: how could i reach each myUserControl and textBoxes on this
myUserControl.
it could be betterif i reach them directly, i know renaming a control on the runtime is useless. what should i do?


\\\
DirectCast(Me.UserControl1.Controls(12), TextBox).Select(2, 10)
///
another issue is, it is not known how many myUserControls on thye from or textboxes on a myUserControl will be created. i need autoscroll
functionality. on the panel it works, but on the form it seems, autoscroll does not work.


Mhm... It should work...

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 16 '05 #8
emid

1. Vertical scrolling will happen only if your controls overflows
vertically. To test this, place controls which overflows horizontally and
vertically. Form will bring both scroll bars.

2. If the controls are created dynamically, to reach individual control, you
have to access Control Collection of your usercontrol

Shak.
"e-mid" <someone@somewhere> wrote in message
news:eb**************@TK2MSFTNGP09.phx.gbl...

"Shakir Hussain" <sh**@fakedomain.com> wrote in message
news:#j**************@tk2msftngp13.phx.gbl...
e-mid.

There are different ways to do that, i have one recomendation.

1. To reach individual controls, access through properties.

example -

protected TextBox mMyTextBox;

public TexBox MyTextBox
{
get {return mMyTextBox;}
i dont think, this way works. controls created dynamically.
another question arised here , is this controls are private by default?
2. Autoscroll will work even in design mode of form. I am not sure why
its not working for ur form


it scrolls horizontally, but vertical autoscroll does not work..

i did not understand why?
Shak.
"e-mid" <someone@somewhere> wrote in message
news:Oi**************@TK2MSFTNGP09.phx.gbl...
i have a user control (say myUserControl) that inherits panel, i create some textboxes on myUserControl dynamically, then i create some
myUserControls on the form dynamically with a loop . of course i change name,location etc.. meanwhile.

i have some problems here then.

eg: how could i reach each myUserControl and textBoxes on this
myUserControl.
it could be betterif i reach them directly, i know renaming a
control on
the runtime is useless. what should i do?
another issue is, it is not known how many myUserControls on thye

from or textboxes on a myUserControl will be created. i need autoscroll
functionality. on the panel it works, but on the form it seems, autoscroll does not work.

thnkz



Nov 16 '05 #9
* "e-mid" <someone@somewhere> scripsit:
Herfried, can you explain about this?

DirectCast(Me.UserControl1.Controls(12), TextBox).Select(2, 10)

and i hear about directCast first time, can you point some sources about it?


The 'Controls' collection contains objects of type 'Control'. 'Control'
is the generic type for controls shown on Windows Forms. In order to
access members of an object that is an instance of a class that inherits
from 'Control', you need to cast the object to this class.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 16 '05 #10

"Shakir Hussain" <sh**@fakedomain.com> wrote in message
news:e$**************@TK2MSFTNGP10.phx.gbl...
emid

1. Vertical scrolling will happen only if your controls overflows
vertically. To test this, place controls which overflows horizontally and
vertically. Form will bring both scroll bars.
it overflows vertically too , but vertical scrollbar do not appear
2. If the controls are created dynamically, to reach individual control, you have to access Control Collection of your usercontrol

Shak.


yes that works for myUserControls on the form, but when i want to get
textBoxes on a myUserControl, i get a error : "getEnumator() does not bla
bla....." . i cant traverse through the controls on myUserControl..

another question:
is it possible to reach with the name of the control?
Nov 16 '05 #11
i was using csharp , therefore i did not t know what directcast is, but i
learned know
The 'Controls' collection contains objects of type 'Control'. 'Control'
is the generic type for controls shown on Windows Forms. In order to
access members of an object that is an instance of a class that inherits
from 'Control', you need to cast the object to this class.
ok i got this. but i cant traverse through controls on my userControl . i
got error about getEnumarator()..

and i ask again:

is it possible to reach a control, if i know only its name?
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 16 '05 #12
No. Its not possible to reach control by name. You can write a service
function which will return a control, if you pass a name. In the control
collection, you can check whether a particular control exists calling
"Contains" method. For that you need a control to find out.

Can you paste the complete error messages? I may get a clue whats
happening..

Shak.

"e-mid" <someone@somewhere> wrote in message
news:eC**************@TK2MSFTNGP10.phx.gbl...

"Shakir Hussain" <sh**@fakedomain.com> wrote in message
news:e$**************@TK2MSFTNGP10.phx.gbl...
emid

1. Vertical scrolling will happen only if your controls overflows
vertically. To test this, place controls which overflows horizontally and vertically. Form will bring both scroll bars.
it overflows vertically too , but vertical scrollbar do not appear
2. If the controls are created dynamically, to reach individual control,

you
have to access Control Collection of your usercontrol

Shak.


yes that works for myUserControls on the form, but when i want to get
textBoxes on a myUserControl, i get a error : "getEnumator() does not

bla bla....." . i cant traverse through the controls on myUserControl..

another question:
is it possible to reach with the name of the control?

Nov 16 '05 #13
* "e-mid" <someone@somewhere> scripsit:
is it possible to reach a control, if i know only its name?


Yes, if you provide the mechanism to do that. For example, you can use
an instance of 'Hashtable' to store the (name, control) pairs and easily
look up a control by its name.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 16 '05 #14
thnkz, i will try it..

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:2k*************@uni-berlin.de...
* "e-mid" <someone@somewhere> scripsit:
is it possible to reach a control, if i know only its name?


Yes, if you provide the mechanism to do that. For example, you can use
an instance of 'Hashtable' to store the (name, control) pairs and easily
look up a control by its name.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 16 '05 #15

Here is the error message:

"foreach statement cannot operate on variables of type 'Form1.myUserControl'
because 'Form1.myUserControl' does not contain a definition for
'GetEnumerator', or it is inaccessible"

thnkz
"Shakir Hussain" <sh**@fakedomain.com> wrote in message
news:uI**************@TK2MSFTNGP12.phx.gbl...
No. Its not possible to reach control by name. You can write a service
function which will return a control, if you pass a name. In the control
collection, you can check whether a particular control exists calling
"Contains" method. For that you need a control to find out.

Can you paste the complete error messages? I may get a clue whats
happening..

Shak.

"e-mid" <someone@somewhere> wrote in message
news:eC**************@TK2MSFTNGP10.phx.gbl...

"Shakir Hussain" <sh**@fakedomain.com> wrote in message
news:e$**************@TK2MSFTNGP10.phx.gbl...
emid

1. Vertical scrolling will happen only if your controls overflows
vertically. To test this, place controls which overflows horizontally and vertically. Form will bring both scroll bars.


it overflows vertically too , but vertical scrollbar do not appear
2. If the controls are created dynamically, to reach individual
control, you
have to access Control Collection of your usercontrol

Shak.


yes that works for myUserControls on the form, but when i want to get
textBoxes on a myUserControl, i get a error : "getEnumator() does not

bla
bla....." . i cant traverse through the controls on myUserControl..

another question:
is it possible to reach with the name of the control?


Nov 16 '05 #16
emid,

Try this

foreach(Control pControl in Form1.myUserControl.Controls)
{
//process the control.
}

this wont give compilation error.

Shak.

"e-mid" <someone@somewhere> wrote in message
news:u0**************@TK2MSFTNGP09.phx.gbl...

Here is the error message:

"foreach statement cannot operate on variables of type 'Form1.myUserControl' because 'Form1.myUserControl' does not contain a definition for
'GetEnumerator', or it is inaccessible"

thnkz
"Shakir Hussain" <sh**@fakedomain.com> wrote in message
news:uI**************@TK2MSFTNGP12.phx.gbl...
No. Its not possible to reach control by name. You can write a service
function which will return a control, if you pass a name. In the control
collection, you can check whether a particular control exists calling
"Contains" method. For that you need a control to find out.

Can you paste the complete error messages? I may get a clue whats
happening..

Shak.

"e-mid" <someone@somewhere> wrote in message
news:eC**************@TK2MSFTNGP10.phx.gbl...

"Shakir Hussain" <sh**@fakedomain.com> wrote in message
news:e$**************@TK2MSFTNGP10.phx.gbl...
> emid
>
> 1. Vertical scrolling will happen only if your controls overflows
> vertically. To test this, place controls which overflows
horizontally
and
> vertically. Form will bring both scroll bars.

it overflows vertically too , but vertical scrollbar do not appear

> 2. If the controls are created dynamically, to reach individual control, you
> have to access Control Collection of your usercontrol
>
> Shak.

yes that works for myUserControls on the form, but when i want to get
textBoxes on a myUserControl, i get a error : "getEnumator() does

not bla
bla....." . i cant traverse through the controls on myUserControl..

another question:
is it possible to reach with the name of the control?



Nov 16 '05 #17
thknz ...
Shak.

"Shakir Hussain" <sh**@fakedomain.com> wrote in message
news:uO**************@TK2MSFTNGP11.phx.gbl...
emid,

Try this

foreach(Control pControl in Form1.myUserControl.Controls)
{
//process the control.
}

this wont give compilation error.

Shak.

"e-mid" <someone@somewhere> wrote in message
news:u0**************@TK2MSFTNGP09.phx.gbl...

Here is the error message:

"foreach statement cannot operate on variables of type

'Form1.myUserControl'
because 'Form1.myUserControl' does not contain a definition for
'GetEnumerator', or it is inaccessible"

thnkz
"Shakir Hussain" <sh**@fakedomain.com> wrote in message
news:uI**************@TK2MSFTNGP12.phx.gbl...
No. Its not possible to reach control by name. You can write a service
function which will return a control, if you pass a name. In the control collection, you can check whether a particular control exists calling
"Contains" method. For that you need a control to find out.

Can you paste the complete error messages? I may get a clue whats
happening..

Shak.

"e-mid" <someone@somewhere> wrote in message
news:eC**************@TK2MSFTNGP10.phx.gbl...
>
> "Shakir Hussain" <sh**@fakedomain.com> wrote in message
> news:e$**************@TK2MSFTNGP10.phx.gbl...
> > emid
> >
> > 1. Vertical scrolling will happen only if your controls overflows
> > vertically. To test this, place controls which overflows horizontally and
> > vertically. Form will bring both scroll bars.
>
> it overflows vertically too , but vertical scrollbar do not appear
>
> > 2. If the controls are created dynamically, to reach individual

control,
> you
> > have to access Control Collection of your usercontrol
> >
> > Shak.
>
> yes that works for myUserControls on the form, but when i want to get > textBoxes on a myUserControl, i get a error : "getEnumator() does not bla
> bla....." . i cant traverse through the controls on myUserControl..
>
> another question:
> is it possible to reach with the name of the control?
>
>



Nov 16 '05 #18

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

Similar topics

3
4745
by: Eddie de Bear | last post by:
Hi, A project I am working on has a requirement for dynamic menus. For the most part this works really well. The menus I'm creating a based on files and directories, so naturally the menu...
2
16229
by: charliewest | last post by:
I need to create textboxes in real-time, the actual number of which is determine by a result from a database query. I have been able to create the controls, and then add them to the ASPX page....
2
2541
by: Dave Williamson | last post by:
When a ASPX page is created with dynamic controls based on what the user is doing the programmer must recreate the dynamic controls again on PostBack in the Page_Load so that it's events are wired...
4
2689
by: spx27 | last post by:
Does anyone know the best way to handle passing a dynamic menu generated from a login from one asp.net page to another. Would it be better to recreate the menu on each page? Save the menu as a...
1
1194
by: Homam | last post by:
So I have a composite paging control that shoulld be positioned on the page like this: PagNav ResultSetDisplay PagNav I know that I can't resuse the PagNav more than once in the form, so I...
3
1701
by: vodafone | last post by:
Hy all I've a little problem. I need to write a dynamic page that render control according to validation status return from previous control validation status. To be clear, I've page that...
0
1575
by: Prodip K Saha | last post by:
Many Programmers stay away from loading User Control dynamically on the Web Form because of the complexity associated with it's state management and event handling. It is easy to load a User...
0
1117
by: Paul | last post by:
Hi! I have been wondering about a design issue for some time now and hope someone can help sort this one out for me. Say you have to create some webcontrols dynamically. Each controls creation...
13
10145
by: rn5a | last post by:
In a shopping cart app, suppose a user has placed 5 orders, I want to show him 5 LinkButtons (one for each order) so that when he clicks the first LinkButton, he would be shown the details of his...
1
4870
by: cdmsenthil | last post by:
I have an Infragistics UltrawebGrid . Each Row in the grid is attached to a context menu using Infragistics CSOM Upon click on the menu, I am creating an Iframe dynamically which points to...
0
7202
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7330
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
5014
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3167
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1512
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
380
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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

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