Click here to Skip to main content
16,018,092 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
SQL
string[] x = new string[] { "NAME", "SEX", "AGE", "SCHOOL"};
        public void ClearControls(TextBox[] A)
        {
            foreach (TextBox a in A)
            {
                a.Text = x;
            }

The method is intended to assign elements of x to some textboxes. The statement: a.Text=x; is the problem. I would appreciate it modified for me.
Thank you.
Posted
Comments
[no name] 5-May-14 13:05pm    
Well you are not assigning elements of x to textboxes, you are assigning x. And you are trying to assign x to all of your textboxes.

A should be a method that gets a list of all the textboxes in the form.
Have a counter that increments and keep assigning a.Text =x[counter];
 
Share this answer
 
v2
Comments
Salisu Shaibu 5-May-14 13:23pm    
Not exactly what I wanted but very useful to my code vocabulary.
U're appreciated.
Thank you.
x is an array.

Perhaps what you want is something similar to

C#
for (Int32 i = 0; i < A.Length; i++)
{
 A[i].Text = x[i];
}


Add the proper checking for nulls, etc, etc.
 
Share this answer
 
Comments
Salisu Shaibu 5-May-14 13:16pm    
Thanks a lot for taking me on revision, I was too minded on advance way of doing things and became ignorant of the simple ways I use to do things.
U're appreciated.
ZurdoDev 5-May-14 13:42pm    
No problem. I love foreach compared to for i loops and sometimes I start writing a foreach on an object that doesn't support it and I have to change it back to for i loop. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900