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

adding Textboxes dynamically into a winform

Hello

I want to add some dynamic control in the win form when i press a button
I write the following line of code. But the problem is instead of displaying
10 textbox it display 9 textboxes.But it display another textbox when i hit
the button again. Can any one pls give me any solution of it. Anyother
alternative solution is appriciable as well.

Thanks

private void btnProcessNow_Click(object sender, System.EventArgs e)

{

int x=750;

int y=300;

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

{

this.SuspendLayout();

this.grpFieldPanel.SuspendLayout();

TextBox a=new TextBox();

a.Anchor = (System.Windows.Forms.AnchorStyles.Top |
System.Windows.Forms.AnchorStyles.Right);

a.Location= new System.Drawing.Point(x,y);

a.Name="a"+i;

a.Size = new System.Drawing.Size(100,20);

y=y+30;

this.grpFieldPanel.SendToBack();

this.grpFieldPanel.Controls.Add(a);

this.Controls.Add(a);

this.grpFieldPanel.ResumeLayout(false);

this.ResumeLayout(false);

}

}

Nov 15 '05 #1
1 4668
Shayer,

I think that you should only be adding the new TextBox to either to the
grpFieldPanel variable (whatever control that might be), or the Controls
collection. A control can have at most only one parent and I think this
might be part of the problem.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Shayer" <sh*******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Hello

I want to add some dynamic control in the win form when i press a button
I write the following line of code. But the problem is instead of displaying 10 textbox it display 9 textboxes.But it display another textbox when i hit the button again. Can any one pls give me any solution of it. Anyother
alternative solution is appriciable as well.

Thanks

private void btnProcessNow_Click(object sender, System.EventArgs e)

{

int x=750;

int y=300;

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

{

this.SuspendLayout();

this.grpFieldPanel.SuspendLayout();

TextBox a=new TextBox();

a.Anchor = (System.Windows.Forms.AnchorStyles.Top |
System.Windows.Forms.AnchorStyles.Right);

a.Location= new System.Drawing.Point(x,y);

a.Name="a"+i;

a.Size = new System.Drawing.Size(100,20);

y=y+30;

this.grpFieldPanel.SendToBack();

this.grpFieldPanel.Controls.Add(a);

this.Controls.Add(a);

this.grpFieldPanel.ResumeLayout(false);

this.ResumeLayout(false);

}

}

Nov 15 '05 #2

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

Similar topics

3
by: Aaron Ackerman | last post by:
I have a bound combobox the appears on a cell within the column of my bound grid when the user clicks on a cell n(In my vb.net WinForm app). I am trying to allow the adding of an item to that bound...
2
by: Briand | last post by:
In my previous posting I failed miserably, to give enough information to get my difficulty apparent. So to start again. I want to create textboxes dynamically in VB.NET. This is not a web...
3
by: ram | last post by:
I have a user control uc (with a dropdownlist uc_dd) that I dynamically add to a pane on a button_click. this pane is hosted on the winform. now when I add two instances of the user control...
15
by: crjunk | last post by:
I have 4 TextBoxes on my form that I'm trying to add together to get a grand total. Here is the code I'm using: <SCRIPT LANGUAGE="JavaScript"> <!-- Beginning of JavaScript - function...
6
by: Dany P. Wu | last post by:
Hi everyone, I created a page which contains a two-column table. The first column has a bunch of labels, and the second a bunch of textboxes. Here's the code: ...
0
by: Sileesh | last post by:
Hi I have html table and a Button in an Aspx page. I am adding one row with some textboxes to Html table each time i click on the Button thru Javascript. Now problem is when when i try to...
4
by: Alex Denton | last post by:
Okay, here's my problem: I need to populate different fields in an HTML table with TextBoxes. For example, if I had 3 columns "Name", "Address", and "City"; I need to have a TextBox in all of...
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...
1
by: Sirisha | last post by:
Hi, I want javascript for displaying multiple textboxes dynamically. ADD-this is button. if i click button first time it will display 1 textbox and if i click 2nd time it will display another...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.