Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Newbie question
Message
De
06/07/2010 09:49:48
 
 
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Titre:
Versions des environnements
Environment:
C# 3.0
Divers
Thread ID:
01471507
Message ID:
01471512
Vues:
58
>>>Here's a newbie C#
>>>
>>>I could write the code below in a few lines in VFP
>>>
>>>This isn't so bad but now now I have a similar situation with 52 values
>>>
>>>What's the best way to do this in VS 2008? (not VS 2010)
>>>
>>>
>>>
>>> switch (column)
>>>        {
>>>        case 0:
>>>          textBoxColumn1.Text = stack[column, row].ToString();
>>>          textBoxColumn1.ForeColor = textboxforecolor; 
>>>          break;
>>>        case 1: 
>>>           textBoxColumn2.Text = stack[column, row].ToString();
>>>           textBoxColumn2.ForeColor = textboxforecolor; 
>>>          break;
>>>        case 2:
>>>          textBoxColumn3.Text = stack[column, row].ToString();
>>>          textBoxColumn3.ForeColor = textboxforecolor; 
>>>           break;
>>>        case 3:
>>>          textBoxColumn4.Text = stack[column, row].ToString();
>>>          textBoxColumn4.ForeColor = textboxforecolor; 
>>>   
>>>          break;
>>>        case 4:
>>>          textBoxColumn5.Text = stack[column, row].ToString();
>>>          textBoxColumn5.ForeColor = textboxforecolor; 
>>>   
>>>          break;
>>>        case 5:
>>>          textBoxColumn6.Text = stack[column, row].ToString();
>>>          textBoxColumn6.ForeColor = textboxforecolor; 
>>>          break;
>>>        case 6:
>>>          textBoxColumn7.Text = stack[column, row].ToString();
>>>          textBoxColumn7.ForeColor = textboxforecolor; 
>>>         break; 
>>>        } 
>>>     
>>>
>>
>>Assuming the textBoxColumnX items are textboxes (and that they exist):
string s = "textBoxColumn" + column.ToString();
>>((TextBox)this.Controls.Find(s, true)[0]).ForeColor = textboxforecolor;
>
>What about assignment of array's value?

Same principle (shrug):
TextBox t = (TextBox)this.Controls.Find(s, true)[0];
t.Text = stack[column,row].ToString();
t.ForeColor = textboxforecolor;
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform