Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
In Foxpro you may use addobject() to add an object of any name to an existing object. These objects may be of any name or number and their names and numbers and types can be completely data driven. In C# however, I have not found a way to do this. In C# you must declare the objects name and know exactly how many objects you need at compile time. Does anyone know how to make the name and number of added objects data driven in C# .net.
thanks
Scott

C# and Foxpro are completely different things. C# is a programming language, Foxpro is a database language.
but of course you can add objects on the fly:
All you need to do is create a new instance of the control you want to create, set it's attributes and then add this.Controls.Add([yourcontrol);
example:
//lets pretend that you have read a database that defines a bunch of labelswhile(Reader.Read())
{
System.Windows.Forms.Label newLabel = new Label();
newLabel.AutoSize = true;
newLabel.BackColor = System.Drawing.SystemColors.Control;
newLabel.Enabled = true;
newLabel.Left = int.parse(Reader["Left"].ToString());
newLabel.Name = Reader["labelname"].ToString();
newLabel.Parent = this;
newLabel.Text = [database text value];newLabel.Top = int.parse(Reader["Top"].ToString());
newLabel.Width = int.parse(Reader["Width"].ToString());
this.Controls.Add(newLabel);
hope this helps,
ChiHappy Decemberween, Everybody!

![]() |
When to use ALT instead o...
|
MySQL ERROR 2003
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |