473,661 Members | 2,501 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.De tailWidget x;

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

{

x = new CustControls.De tailWidget();

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

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

this.pnlDetailC ontainer.Contro ls.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 42573
Your code snippet looks right. Why don't you check programmaticall y if all
the controls are in the container, say

foreach (Control x in this.pnlDetailC ontainer.Contro ls)
{
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******** *******@tk2msft ngp13.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.De tailWidget x;

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

{

x = new CustControls.De tailWidget();

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

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

this.pnlDetailC ontainer.Contro ls.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(o bject sender, System.EventArg s e)
{
for(int i=0;i<5;i++)
{
TextBox tb=new TextBox();
tb.Text="textbo x"+ i.ToString();
tb.ID=i.ToStrin g();
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
3721
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 the Controls.Add() method several times or even calling the Controls.AddRange() method once can take a huge amount of time. Therefore, I would like to be able to run the loop that creates the controls on a different thread and meanwhile give the user...
1
11035
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
1686
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 of code blocks (<% %>) on the page. Most of these blocks can be handled by adding a label control to the form so it is not that big of deal, but one of the things being posted is the page title. I am not sure how I can access that from the code...
1
1653
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 web form, no controls loaded 2. user selects registration type (1 of 4 possible types) from a dropdown control 3. the dropdown properties are : autopostback=True OnSelectedIndexChanged="displayUserGroupControl" 4. Now when my...
3
2339
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 page. So whenever the Admin person comes to know about the new category in the market he will be adding as different Sub-Categories for example ABAP, BDC etc..etc.. on every click event as Checkboxes. And these controls(checkboxes) should remain...
0
1497
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 go out of view with no scrolling option. If I resize the App., the Controls start coming into view, so I know they're there. The Panel isn't showing Vertical Scrollbars to be abel to see them. IS there soemthing I'm doing wrong or forgetting? ...
6
1525
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 before,how can i unload it?? pls help me,thanks
3
5486
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 following error when the DDL is added (but not the Label): "Control 'ctl07' of type 'DropDownList' must be placed inside a form tag
4
4475
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 selected, the row is added using JavaScript. The script uses cloneNode to clone a hidden template row and all of its children and then adds the new row to the table, updates all of the child control Ids and sets visibility etc. The hidden...
0
8432
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8343
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8855
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8758
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8545
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7364
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6185
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
2
1986
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1743
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.