Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Help building string to add to listbox
Message
De
06/12/2007 08:54:44
 
 
À
06/12/2007 08:47:41
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, États-Unis
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
VB 8.0
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Divers
Thread ID:
01273456
Message ID:
01273558
Vues:
13
>>>>Hoping someone can guide an C# newbie. I'm looping through an array, and I want to add each element to a listbox on the form. But for each item, I want to preference it with the element name/number. I can't get past the compiler error with the code below, but if I remove the ctext="PID:" += i.ToString(); line it does add the text of the array item to the listbox.
>>>>
>>>>
>>>>PID:1 element 1 text
>>>>PID:2 element 2 text
>>>>...
>>>>
>>>>
>>>>
>>>
>>>Try the updated code:
>>>
>>>            string[] PID_Data = PIDString.Split(fieldSplitter);
>>>            // Loop through each item and add to listbox
>>>            string ctext = String.Empty;
>>>            for(int i=0;i<PID_Data.Length;i++)
>>>            {
>>>                ctext = "PID: " & i.ToString() & PID_Data[i];
>>>                listBox1.Items.Add(ctext);
>>>                ctext = String.Empty;
>>>            }
>>>
>>
>>Hmm. This is in the VB.NET section but sure as heck won't run under VB. Never mind - you've made sure it won't even complile under C# either <g>
>>Best,
>>Viv
>
>What is wrong with it? I took my best shot but know nothing about C#.
ctext = "PID: " & i.ToString() & PID_Data[i];
//would be:
ctext = "PID: " AND i.ToString() AND PID_Data(i);
//in VB
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform