473,386 Members | 1,886 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,386 software developers and data experts.

Adding controls to a panel dynamically.

Hi all,

I'm having a problem adding controls to a panel dynamically. I have a
usercontrol that I create and try to add 5 times to the panel, but I only
ever see the first control. I know it's the first, because a property of
the userControl is to display it's name. The code I have is:

//Add detatil widgets to the panel

CustControls.DetailWidget x;

for (int i = 0; i<5; i++)

{

x = new CustControls.DetailWidget();

x.Name = "asdf" + i.ToString();

x.Location = new Point(i * 10, i * 10);

this.pnlDetailContainer.Controls.Add(x);

}

How is this supposed to work? Should the panel automatically place each
control under one another or next to one another or must that be done
entirely by hand?

Thanks!

-D
Nov 15 '05 #1
2 42530
Your code snippet looks right. Why don't you check programmatically if all
the controls are in the container, say

foreach (Control x in this.pnlDetailContainer.Controls)
{
MessageBox.Show(x.Name);
}

If you see all the added controls, then may be it's a paint issue or
something to do with your control itself (like your control choosing its own
location, etc.)

-vJ

"Big D" <a@a.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
Hi all,

I'm having a problem adding controls to a panel dynamically. I have a
usercontrol that I create and try to add 5 times to the panel, but I only
ever see the first control. I know it's the first, because a property of
the userControl is to display it's name. The code I have is:

//Add detatil widgets to the panel

CustControls.DetailWidget x;

for (int i = 0; i<5; i++)

{

x = new CustControls.DetailWidget();

x.Name = "asdf" + i.ToString();

x.Location = new Point(i * 10, i * 10);

this.pnlDetailContainer.Controls.Add(x);

}

How is this supposed to work? Should the panel automatically place each
control under one another or next to one another or must that be done
entirely by hand?

Thanks!

-D

Nov 15 '05 #2

Hi

I think the problem should be your user control, because I have tried to
add 5 textbox into the panel, it just works well, code snippet like this:

private void Button1_Click(object sender, System.EventArgs e)
{
for(int i=0;i<5;i++)
{
TextBox tb=new TextBox();
tb.Text="textbox"+ i.ToString();
tb.ID=i.ToString();
Panel1.Controls.Add(tb);
}
}

I think you should check the implement of your user control.

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.

Nov 15 '05 #3

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

Similar topics

2
by: avivgur | last post by:
Hello, I am writing a program in Visual C# and I have encountered a problem. In my program I want to dynamically create a multitude of controls (thousands) on a form. The problem is that calling...
1
by: Alessandro Fragnani | last post by:
Hi, I would like to know how to avoid flicker while adding controls to a panel. I couldn´t find any kind of "BeginUpdate/EndUpdate" on it. Thanks in advance Alessandro
5
by: Jeremy Ames | last post by:
I have run into a major road block with my page development projects. I am trying to add a literal control to my asp.net page and I got an error stating that the control could not be added because...
1
by: C Downey | last post by:
I have a registration form that should load different web user controls based on the selection of a dropdown list. Basically, the user follows the following steps: 1. user comes to very basic...
3
by: Ankit Aneja | last post by:
I have a strange situation and I have no idea how to solve this. Its a Recruitment Search Page,in the Admin Page, for every button click event the Admin Person has to create a checkbox on the users...
0
by: spikedpunchvictim | last post by:
Maybe someone here can help me. I am programatically adding Controls to a Panel whose AutoScroll Property is set to True. When I add more controls than can visually fit on the Panel, they just...
6
by: crazyjh | last post by:
hello i want to add some controls in according of the time. but when the time change, i call the method again to add controls again,No effect! i think maybe i should unload the controls adding...
3
by: Mark Denardo | last post by:
I'm trying to dynamically create and add controls to a web page: Label obj1 = new Label(); DropDownList obj2 = new DropDownList(); Controls.Add(obj1); Controls.Add(obj2); But I get the...
4
by: Lewis Holmes | last post by:
Hi I have the following situation in one of my asp.net pages. The user can add multiple table rows to a form by selecting a button. These rows can contain asp.net controls. When this button is...
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: 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: 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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.