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

How to copy values from textbox into array of labels?

Hi
So here is the problem: When I click on the button bStart only one value is copied and replaced in one labe from the array of labels. This should work like this: After the user clicks on the button bStart, all values from the textbox txtVnes should be copied in each label in the array of labels. All the labels have text "Z", and after click on the button they should be changed with the values in the textbox txtVnes. As you can see i used l.Text = txtVnes.Text; to copy the values, but it doesn't work. I appreciate if you can help me, thank you!

Expand|Select|Wrap|Line Numbers
  1. public partial class Form1 : Form
  2. {
  3.     private Label l;
  4.     private Button  bStart;
  5.     private TextBox txtVnes;
  6.     private Label[] pole;
  7.  
  8.  public Form1()
  9.     {
  10.         InitializeComponent();
  11.         bStart = new Button();
  12.         bStart.Location = new Point(240, 165);
  13.         bStart.Width = 75;
  14.         bStart.Height = 25;
  15.         bStart.Text = "START";
  16.  
  17.          txtVnes = new TextBox();
  18.         txtVnes.Location = new Point(240, 10);
  19.         txtVnes.Width = 160;
  20.         txtVnes.Height = 130;
  21.         txtVnes.Multiline = true;
  22.  
  23.         int a = 0;
  24.         pole = new Label[42];
  25.         for (int i = 1; i <= 6; i++)
  26.         {
  27.             for (int j = 1; j <= 7; j++)
  28.             {
  29.                 l = new Label();
  30.                 l.Name = "label" + i.ToString() + j.ToString();
  31.                 l.Text = "Z";
  32.                 l.Width = 20;
  33.                 l.Height = 20;
  34.                 l.TextAlign = ContentAlignment.MiddleCenter;
  35.                 l.Parent = this;
  36.                 l.BackColor = Color.FromArgb(100, 149, 237);
  37.                 l.Location = new Point(10 + (j - 1) * 25, 15 + (i - 1) * 25);
  38.                 pole[a] = l;
  39.                 a++;
  40.  
  41.             }
  42.         }
  43.  
  44.          this.Controls.Add(bStart);
  45.          this.Controls.Add(txtVnes);
  46.          this.Controls.Add(l);
  47.          bStart.Click+=new EventHandler(bStart_Click);
  48.  
  49.       }
  50.  
  51.      private void bStart_Click(object sender, EventArgs e)
  52.     {
  53.  
  54.         Regex regex = new Regex(@"^(\s)*(\d ){6}\d(\s)*$");
  55.         bool isValid = true;
  56.         string[] ts = txtVnes.Text.Split(new string[] { "\r\n" },     
  57.         StringSplitOptions.RemoveEmptyEntries);
  58.  
  59.  
  60.         if (ts == null || ts.Length < 1 || ts.Length > 6)
  61.         {
  62.             MessageBox.Show("Not valid");
  63.         }
  64.         else
  65.         {
  66.             foreach (string t in ts)
  67.             {
  68.                 if (regex.IsMatch(t) == false)
  69.                 {
  70.                     MessageBox.Show("Not valid");
  71.                     break;
  72.                 }
  73.             }
  74.  
  75.         }
  76.         if (isValid)
  77.         {
  78.  
  79.  
  80.           l.Text = txtVnes.Text;
  81.  
  82.         }
  83.        }
  84.  
Jan 7 '12 #1
2 2783
Rabbit
12,516 Expert Mod 8TB
That's because you don't loop through your labels. l is just a single label.
Jan 7 '12 #2
Loop through your labels and assign them the text from respective textbox
Jan 27 '12 #3

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

Similar topics

3
by: Ben | last post by:
Hi all, This may sound easy but I'm having trouble assigning values to array element. My problem is as follows: m = for o in m: # Here first o is 'Peter'.. I want to do something like this:...
4
by: stelladiary2004 | last post by:
Hi! I would appreciate some help with this (basic) question. I need to copy an 2D array x to another 2D array y. I know how to do it copying element by element, but I would like to use a faster...
3
by: trickish | last post by:
In my main I try to get values assigned to "int *thisSoduko" through the static method Reader::read. int main(char *args) { ... int *thisSoduko = new int; if(Reader::read( fileName,...
2
by: Matthias S. | last post by:
Hi, I'm just wondering about the easiest way to copy certain values from a collection to a simple array. Say I've got a class (RaceCarDriver) with a DateFirstRace property. Now I'd like to...
3
by: Newcomsas | last post by:
Hello, I'm trying to solve a problem with JS textbox array without success. I have two buttons in my page: PLUS and MINUS; at every click on PLUS a new textbox named 'dear' is generated. So, if...
2
by: TheDr | last post by:
Hello. New to this site and to VB as you're about to discover... My problem seems simple: I require to copy values from my VB program to populate a spreadsheet. More Specifically the values...
1
by: seadog | last post by:
Hi, I am having a problem displaying data in a textbox array. What I am trying to do is have 5 number enter 5 textboxes, starting from the first and working there way to the bottom textbox. What...
1
by: Pia Stevens | last post by:
I have 2 arrays string arr1; string arr2; Ok there are two way to copy arr1 into arr2: With Array.Copy() and
1
by: anwar7517525 | last post by:
Dearest how can i find three smallest values in array I solve it by sorting array in ASC Order then i print first three values but i want to another efficient way can you have any efficient way
3
by: nady | last post by:
Dear Techies, I have a code which retrieves values from database cmdSelect = New OleDbCommand("select fields,finesFields from trafficReport where checked LIKE 1", conn) cmdSelectDr =...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...

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.