3 Replies - 4660 Views - Last Post: 12 April 2011 - 04:45 AM Rate Topic: -----

#1 devilonline  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 11-April 11

String Array To TextBox Array

Posted 11 April 2011 - 09:15 PM

Hi,I have this code:

string[] cores;
            cores = new string[3];
            cores[0] = "red";
            cores[1] = "green";
            cores[2] = "blue";

            foreach (string cor in cores)
            {
          
                MessageBox.Show (cor);
            }



how can it makes an text field for each item and so put each in a diferente text field?

thanks

Is This A Good Question/Topic? 0
  • +

Replies To: String Array To TextBox Array

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5529
  • View blog
  • Posts: 11,839
  • Joined: 02-June 10

Re: String Array To TextBox Array

Posted 11 April 2011 - 09:35 PM

First: You question is hard to understand. "text field" doesn't mean anything in C#. Do you mean you want to make a TextBox for each item in your array, then put an array value into each TextBox? As much as we could explain how to programmatically make, I seriously doubt you will understand it.

Start by learning the C# language though a book or on-line tutorials.
You need to start with "Hello World" just like every other programmer and work your way from there.


Standard resources, references and suggestions for new programmers.

I am going to guess that you are trying to teach yourself C# without much guidance, a decent book or without knowing where to look. Sometimes just knowing where to look can make all the difference. Google is your friend.
Search with either "C#" or "MSDN" as the first word: "MSDN Picturebox", "C# Custom Events", "MSDN timer" etc.

But honestly, just typing away and seeing what pops up in Intellisense is going to make your self-education take 20 years. You can learn by trying to reverse engineer the language through banging on the keyboard experimentation - or you can learn by doing the tutorials and following a good "How to learn C#" book.

May I suggest picking up a basic C# introductory book? There are so many great "How do I build my first application" tutorials on the web... There are dozens of "Learn C# in 21 days", "My first C# program" type books at your local book seller or even public library.

C# resources. Start here
Intro to C# online tutorial then here...
C# control structures then here.
MSDN Beginner Developer video series
MSDN video on OOP principals, making classes, constructors, accessors and method overloading

The tutorials below walk through making an application including inheritance, custom events and custom controls.
Quick and easy custom events
Bulding an application - Part 1
Building an application - Part 2
Passing values between forms/classes
Debugging tutorial
Working with environmental variables

Debugging tutorial
Debugging tips
Great debugging tips

Build a Program Now! in Visual C# by Microsoft Press, ISBN 0-7356-2542-5
is a terrific book that has you build a Windows Forms application, a WPF app, a database application, your own web browser.

C# Cookbooks
Are a great place to get good code, broken down by need, written by coding professionals. You can use the code as-is, but take the time to actually study it. These professionals write in a certain style for a reason developed by years of experience and heartache.

Microsoft Visual Studio Tips, 251 ways to improve your productivity, Microsoft press, ISBN 0-7356-2640-5
Has many, many great, real-world tips that I use all the time.

Writing a text file is always one of the first things people want to do, in order to store data like high-scores, preferences and so on
Writing a text file tutorial.
Reading a text file tutorial.


These are just good every-day references to put in your bookmarks.
MSDN C# Developers Center with tutorials
Welcome to Visual Studio

Have you seen the 500+ MSDN Code Samples? They spent a lot of time creating samples and demos. It seems a shame to not use them.

Let me also throw in a couple tips:
  • You have to program as if everything breaks, nothing works, the cyberworld is not perfect, the attached hardware is flakey, the network is slow and unreliable, the harddrive is about to fail, every method will return an error and every user will do their best to break your software. Confirm everything. Range check every value. Make no assumptions or presumptions.
  • Take the extra 3 seconds to rename your controls each time you drag them onto a form. The default names of button1, button2... button54 aren't very helpful. If you rename them right away to something like btnOk, btnCancel, btnSend etc. it helps tremendously when you make the methods for them because they are named after the button by the designer.
    btnSend_Click(object sender, eventargs e) is a lot easier to maintain than button1_click(object sender, eventargs e)
  • You aren't paying for variable names by the byte. So instead of variables names of a, b, c go ahead and use meaningful names like Index, TimeOut, Row, Column and so on

Was This Post Helpful? 0
  • +
  • -

#3 marinus  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 135
  • View blog
  • Posts: 575
  • Joined: 14-April 10

Re: String Array To TextBox Array

Posted 11 April 2011 - 10:52 PM

string[] cores;
	            cores = new string[3];
	            cores[0] = "red";
	            cores[1] = "green";
	            cores[2] = "blue";
	 
	            for(int i=0;  i < cores.Length; i++)
	            {
	                TextBox tb = new TextBox();
                        tb.Text = cores[i];
                        
	                MessageBox.Show (cor);
	            }




Then add that textbox to whatever ,Panel,GroupBox control
with MYControl.Controls.Add(tb); to add it in you page
but be careful the textboxes will be on top of each other ,
you will have to define each individual textbox own position..

This post has been edited by marinus: 11 April 2011 - 10:57 PM

Was This Post Helpful? 0
  • +
  • -

#4 Sergio Tapia  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1253
  • View blog
  • Posts: 4,168
  • Joined: 27-January 10

Re: String Array To TextBox Array

Posted 12 April 2011 - 04:45 AM

I'm guessing you want to add whatever is inside of each TextBox into the array. There's not much you need to change.

You can go:

string[] colors = new string[3];

colors[0] = TextBox1.Text;
colors[1] = TextBox2.Text;
colors[2] = TextBox3.Text;



The TextBox control has a .Text property which returns the current text that it has inside. Hope this helps. :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1