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

How to Add Controls dynamically ?

Hi,

I'm new to C#. I want to add a TabPage dynamically (name depends on data from database). After receiving the data the TabPage tab should be added to the TabControl ( this.Services) but nothing happens. Putting the code somewhere else (without the database dependency) doensn't work either. Even adding items to a ListBox dynamicly doesn't work. Can someone tell me what I have to do to add / create Controls dynamically at runtime?


Expand|Select|Wrap|Line Numbers
  1.  TabPage tab = new System.Windows.Forms.TabPage();
  2.                     tab.Location = new System.Drawing.Point(4, 22);
  3.                     tab.Name = reader.GetString(0);
  4.                     tab.Padding = new System.Windows.Forms.Padding(3);
  5.                     tab.Size = new System.Drawing.Size(670, 335);
  6.                     tab.TabIndex = 3;// this.Services.Controls.Count + 1;
  7.                     tab.Text = reader.GetString(0);
  8.                     tab.UseVisualStyleBackColor = true;
  9.                     this.Services.Controls.Add(tab);
thanks,

Crystallugia
Oct 1 '10 #1
2 2409
GaryTexmo
1,501 Expert 1GB
You need to add it to the TabPages for a TabControl, not the Controls. In your case...

Expand|Select|Wrap|Line Numbers
  1. TabPage tab = new System.Windows.Forms.TabPage();
  2. tab.Location = new System.Drawing.Point(4, 22);
  3. tab.Name = reader.GetString(0);
  4. tab.Padding = new System.Windows.Forms.Padding(3);
  5. tab.Size = new System.Drawing.Size(670, 335);
  6. tab.TabIndex = 3;// this.Services.Controls.Count + 1;
  7. tab.Text = reader.GetString(0);
  8. tab.UseVisualStyleBackColor = true;
  9. //this.Services.Controls.Add(tab);
  10. this.Services.TabPages.Add(tab);
  11.  
Oct 4 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: macca | last post by:
Hi, I am writing a GUI application. It will have a number of user defined controls( I plan to use/create a user defined control that will output alarm states that the user can also select and...
1
by: Jill Graham | last post by:
Hi, I can use following syntax to add user controls directly to my pages : <XYZ:myControl parameter1="value1" parameter2="value2" runat="server" /> The control "myControl" is executed using...
3
by: Guadala Harry | last post by:
I have this scenario: ASPX Page dynamically loads userControl1 - which in turn dynamically loads userControl2. UserControl2 contains a TextBox Web Server control. When a user clicks a button in...
1
by: Jeffrey Todd | last post by:
I have successfully created functionality that mostly models what I'm trying to do - which is dynamically insert controls into a user control (ascx), and insert validation controls, also...
3
by: supvine | last post by:
Hello, I am developing a page that has several custom web user controls that need to be loaded dynamically. Some of the controls are loaded based on the action (button-click) of a different...
0
by: yeltsin27 | last post by:
I need some advice on handling dynamically added controls in a GridView. My app takes an uploaded CSV file containing addresses, converts it to a DataTable, databinds the DataTable to a...
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...
2
by: laxmibokka | last post by:
adding controls dynamically In my asp.net application, i have to add dropdownlist(with yes/no options), and textbox to the table cells dynamically to each row of a table.The table also contains some...
2
by: Raymond Du | last post by:
Hi, I need to find a way to place multiple textboxes and other controls dynamically on a web form, I tried to put a placeholder on a form then create and add controls dynamically into the place...
4
by: mohaaron | last post by:
I can think of a lot of reasons why this might need to be done but as far as I can tell it's not possible. I've been looking for a way to add HtmlTableRows to a table using a button click for a...
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
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
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
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,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.