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

Array of textboxes?

HaLo2FrEeEk
404 256MB
I'm making a program to help me upload files to my site en masse. I've already sorta created the commandline argument portion of it, but I want to create options for each filename passed via commandline, so I can define where on the server each file will go. For example, if I were to select 4 files and pass them to the program via commandline, I want 4 groups of textboxes to show up, with 2 textboxes per group. The first would simply be to show the file to be uploaded, and would be read only, the second would be to define the upload path. I'd probably also have buttons in each group to remove a file fom the upload queue, and a button seperate from the groups to add another group to select another file to upload.

How would I go about making an array (I assume that's what this will need to be) of textboxes that I can iterate through and process each one individually? In PHP I can simply make the name attribute of the textbox something like "somename[]" and no matter how many I have, as long as they're named that name, they will be passed to the script as an array.

I'm not sure if I'm explaining what I want to do properly, so let me know if it doesn't make sense.
Dec 29 '09 #1
2 4394
GaryTexmo
1,501 Expert 1GB
I've done a lot of dynamic control generation like this, it's not so bad once you get the hang of it. A handy tip to remember is that you can name objects that inherit from control, then you can access them from a form object's control list by that name.

Example...

Expand|Select|Wrap|Line Numbers
  1. Button newButton = new Button();
  2. newButton.Name = "btn0";
  3. this.Controls.Add(newButton);
  4.  
  5. ...
  6.  
  7. Button btn0 = this.Controls["btn0"] as Button;
  8. if (btn0 != null) ...
Now, for the generation of your text box array itself, you've got two options.

A) Throw them directly on your form or in a panel, changing the size and location of your text boxes as you generate them. The benefit here is that you can place them exactly where you want them in any order, but you have to keep track of, and increment locations.

B) Put them on a FlowLayoutPanel. This wonderful little control will automatically organize controls you place on it (even when you re-size it!) and you can change properties on the control to change how the controls go on (ie, left to right, up to down, etc...). The plus side is obvious, but the downside is that you can only really get a grid of controls, you can't do anything else.

So, your task broken down further...

1) Define your loop to generate your controls
2) Create a new object for your control
3) Name your object
4) Set it's properties according to whatever guidelines you've defined.
5) Use method A or B above to place the object on your form, or some kind of panel.

Hopefully that gets you started.
Dec 29 '09 #2
HaLo2FrEeEk
404 256MB
Thanks, this is a way better explanation than the other one I found. I did manage to create the array of textboxes, and also was able to read each one's value. Now I think I just need to take it a step further and generate a panel, place my textboxes and buttons on it, then add the panel to the form, allowing me to better control the layout and group the controls more effectively. Hopefully I can make something nicely workable.

I managed to pass the command line arguments (a few files I selected and dragged onto the executable) to the program and generate a new textbox for each argument passed that was a valid filename. I dragged 8 files onto the executable and the program opened with 8 textboxes and a button that I could click that would messagebox the value of each textbox, showing me that my logic is sound and that I can iterate through the array to get the values.

Thank you for the reply, I'll be sure to ask you if I have any more questions.
Dec 29 '09 #3

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

Similar topics

6
by: Bhavin | last post by:
Anybody quickly replies it, would be a great help! I try to create dynamic array of textboxes control in ASP.NET(C#). I got the following error while I tried to assign value to ID property of...
2
by: RBohannon | last post by:
Is it possible to create a control array on an unbound form? I would like to be able to loop through a series of unbound text boxes. Thanks.
1
by: Stephen | last post by:
Was wondering if someone could please help me with an array I'd like to create in an asp.net page. I have to design an array which stores the values of addresses manually entered into textboxes...
3
by: samneefs | last post by:
I'm wondering if there's a way to create an array of textboxes, or loop through textboxes. The textboxes are in an ASP.NET page, but the looping happens through Visual Basic. On page load,...
10
by: Altman | last post by:
In vb 6 you use to be able to create an array of objects and I can't seem to figure this out in .NET. I figured you can't make this but I was wondering how I could do it if I had for instance 3...
3
by: barbara | last post by:
Hi all, I need to use hundreds of textboxes to display data. In VB 6.0, I can assign the value by the loop with a textboxes array. How to do it in VB.net? Thanks a lot.
6
by: Rich | last post by:
Hello, I have an application that contains several checkboxes. I originally created this app in VB.Net 2003 and upgraded the app to VB.Net 2005. I understand the vb2005 supports control...
9
by: jan82 | last post by:
Hi everybody I declared a private static array of textboxes at the top of a class, then i generate the array elements (new textbox()) in a separate function (private void in the same class), ...
1
by: bethmiddy | last post by:
Hello, I am very new to programming and am currently taking a class on VB. This is probably very simple, I just don't get it. I am working on a group project where we need to have 3 columns and...
7
by: Angel López | last post by:
How to do this with Vb.net 2008??? myNumber=1+ Int(Rnd()*90) text(myNumber).backcolor=vbRed Tanks Angel
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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?
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...

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.