473,406 Members | 2,217 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,406 software developers and data experts.

create new controls each iteration of a loop

Hello all,

I have a loop and would like to create a new textbox on each iteration of
the loop. The code below only generates one textbox no matter how many times
the loop loops! Any insight would be greatly appreciated.
int over = 25;
int down = 0;
for (int i = theEmail.Attachments.Count; i > 0; i--)
{
try
{
OL.Attachment attachment =theEmail.Attachments;

string fileStorage=@"c:\" +theEmail.Attachments.DisplayName;
rmaxOutlook.attachmentFormBuilder newAttachTextField=new
attachmentFormBuilder(attachment.DisplayName,fileS torage,i);

TextBox newTxtAttachField = new TextBox();
newTxtAttachField.Width = 338;
newTxtAttachField.Location = new Point(over, down + 25);
newTxtAttachField.Text = attachment.DisplayName;
this.Controls.Add(newTxtAttachField);
attachment.SaveAsFile(@"c:\" + theEmail.Attachments.DisplayName);
}

catch (Exception exc)
{
System.Windows.Forms.MessageBox.Show(exc.ToString( ));
}
}
Dec 7 '05 #1
2 1813
With non-esential code stripped out:

int over = 25;
int down = 0;
for (int i = 10; i > 0; i--)
{
try
{
TextBox newTxtAttachField = new TextBox();
newTxtAttachField.Width = 338;
newTxtAttachField.Location = new Point(over, down + 25);
down+=25;
newTxtAttachField.Text = "box"+i.ToString() ;
newTxtAttachField.Name ="Textbox"+i.ToString();
this.Controls.Add(newTxtAttachField);
}
catch (Exception exc)
{
System.Windows.Forms.MessageBox.Show(exc.ToString( ));
}
}

--Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Mike Mac" wrote:
Hello all,

I have a loop and would like to create a new textbox on each iteration of
the loop. The code below only generates one textbox no matter how many times
the loop loops! Any insight would be greatly appreciated.
int over = 25;
int down = 0;
for (int i = theEmail.Attachments.Count; i > 0; i--)
{
try
{
OL.Attachment attachment =theEmail.Attachments;

string fileStorage=@"c:\" +theEmail.Attachments.DisplayName;
rmaxOutlook.attachmentFormBuilder newAttachTextField=new
attachmentFormBuilder(attachment.DisplayName,fileS torage,i);

TextBox newTxtAttachField = new TextBox();
newTxtAttachField.Width = 338;
newTxtAttachField.Location = new Point(over, down + 25);
newTxtAttachField.Text = attachment.DisplayName;
this.Controls.Add(newTxtAttachField);
attachment.SaveAsFile(@"c:\" + theEmail.Attachments.DisplayName);
}

catch (Exception exc)
{
System.Windows.Forms.MessageBox.Show(exc.ToString( ));
}
}

Dec 7 '05 #2
You never change the variable "down", so you're creating several textboxes
on top of each other. Try "down += 25" instead of "down + 25"
"Mike Mac" <Mike Ma*@discussions.microsoft.com> wrote in message
news:B3**********************************@microsof t.com...
Hello all,

I have a loop and would like to create a new textbox on each iteration of
the loop. The code below only generates one textbox no matter how many
times
the loop loops! Any insight would be greatly appreciated.
int over = 25;
int down = 0;
for (int i = theEmail.Attachments.Count; i > 0; i--)
{
try
{
OL.Attachment attachment =theEmail.Attachments;

string fileStorage=@"c:\" +theEmail.Attachments.DisplayName;
rmaxOutlook.attachmentFormBuilder newAttachTextField=new
attachmentFormBuilder(attachment.DisplayName,fileS torage,i);

TextBox newTxtAttachField = new TextBox();
newTxtAttachField.Width = 338;
newTxtAttachField.Location = new Point(over, down + 25);
newTxtAttachField.Text = attachment.DisplayName;
this.Controls.Add(newTxtAttachField);
attachment.SaveAsFile(@"c:\" + theEmail.Attachments.DisplayName);
}

catch (Exception exc)
{
System.Windows.Forms.MessageBox.Show(exc.ToString( ));
}
}

Dec 7 '05 #3

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

Similar topics

6
by: Rudolf Bargholz | last post by:
Hi , I have the following tables ------------- PAX: Id Order_Id Name Position
4
by: Jeff Rodriguez | last post by:
Main just loops over this while it's not null. The segfault occurs at this line: *line = (char)ch; Also, please don't just fix the code. I would like to know why exactly this isn't working so I...
6
by: SamIAm | last post by:
Hi am creating a email application that needs to mail out a very large amount of emails. I have created a multithreaded c# application that using message queuing. I have created a threadpool of 5...
66
by: Cor | last post by:
Hi, I start a new thread about a discussion from yesterday (or for some of us this morning). It was a not so nice discussion about dynamically removing controls from a panel or what ever. It...
9
by: Jimakos Bilakis | last post by:
Hi everyone! I want to create a function that it will take as parameters a table (float), an integer (the number of Table's rows) and it will re-arrange the elements in the table from the...
7
by: Matt | last post by:
Hi all, I'm trying to create a system where it reads a number of records from a database and then creates a row in the GUI that contains a single field from the database and a button that has a...
32
by: =?Utf-8?B?U2l2?= | last post by:
I have a form that I programmatically generate some check boxes and labels on. Later on when I want to draw the form with different data I want to clear the previously created items and then put...
1
by: greyseal96 | last post by:
Hi, I am a pretty new programmer, so I apologize in andvance if this is a dumb question... In a book that I'm reading to learn C#, it says that when using a foreach() loop, a read-only copy of...
0
by: Hatem Nassrat | last post by:
on Wed Jun 13 10:17:24 CEST 2007, Diez B. Roggisch deets at nospam.web.de wrote: Well I have looked into this and it seems that using the list comprehension is faster, which is...
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
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
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,...
0
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...

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.