473,383 Members | 1,739 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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 1733
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
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
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
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
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
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
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
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
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
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
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

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.