2009-03-13 8 views
0

Je veux afficher une nouvelle ligne dans ma liste sur mon winform. J'ai un code comme celui-ci sur mon cours de revers.Comment insérer et afficher une nouvelle ligne dans le tableau de chaînes?

string[] a = new string[att]; //String array contains the attributes. 
     if (attCol != null) 
      for (int i = 0; i < att; i++) //Loop through entire attributes 
      { 
       a[i] = " Attribute name: " + attCol[i].Name + " , " + "Attribute value: " + attCol[i].Value; //Retrieving attribute name and values from the array. 
      } 
     return a; //returning the string array to be displayed in listbox 

ici retourner une chaîne tableau [] sera retourné à la classe UI qui contient le code comme celui-ci

string[] attributecoll = new string[xNode.Attributes.Count]; //Declaration of String array where all the attributes of selected node are returned 
      attributecoll = classObj.selectedNode(xNode); //calling the selectedNode method from backend class and store it in a string array 
      foreach (string c in attributecoll) 
      { 
       listBox1.Items.Add(c);  //adding the name and values of Attribute in the Listbox 
      } 

Exemple pour l'élément de fichier xml

enter code here 
<person name="John"/> 

Cette affiche attribut nom et valeurs comme ceci dans la liste sur une seule ligne:

Nom d'attribut: Nom, Attribut Valeur: John

Mais je veux qu'il soit affiché comme celui-ci dans listboxas:

Attribut: Nom

Attribut Valeur: John

Pouvez-vous me dire où je vais mal? Merci pour votre aide ...

Répondre

0

Vous pouvez essayer d'ajouter un « \ n » à la chaîne

Mais vous pouvez aussi utiliser un vecteur/liste avec la chaîne de sorte que vous pouvez préfixer l'attribut name et valeur séparée lignes

EDIT: Ce peut-être mieux, réserve deux fois plus de chaînes (* 2) et utiliser 2 lignes pour chaque attribut

string[] a = new string[att*2]; //String array contains the attributes. 
if (attCol != null) 
{ 
    int aIterator = 0; 
    for (int i = 0; i < att; i++) //Loop through entire attributes 
    { 
     a[aIterator++] = " Attribute name: " + attCol[i].Name; 
     a[aIterator++] = "Attribute value: " + attCol[i].Value; 
    } 
} 
return a; //returning the string array to be displayed in listbox 
+0

\ n ne fonctionne pas .... je ne peux pas utiliser vecteur/liste maintenant .. –

+0

J'ai édité mon poste pour une solution – RvdK

Questions connexes