2009-03-13 5 views
0

私はwinformのリストボックスに新しい行を表示したいと思います。私はバックハンドクラスにこのようなコードを持っています。ここ文字列配列に新しい行を挿入して表示する方法は?

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 

文字列が[]配列は、XMLファイルの要素のために、この

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 
      } 

例のようなコードが含まれているUIクラスに

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

を返されます。これは、属性を表示返すリストボックスの名前と値をリストボックスに1行で入力します。

は、属性名:名前は、属性値:ジョン

しかし、私はそれがlistboxasにこのように表示させたい:

は、属性名:

属性値に名前を付ける:ジョン

あなたが教えてもらえますどこが間違っているの?あなたの助けのための おかげで...

答えて

0

あなたは、文字列

に「\ n」を追加してみてくださいすることができます。しかし、あなたが別々に名前と値の属性を付加することができますので、あなたはまた、文字列でベクトル/リストを使用することができますライン

EDIT: これ多分良く、予備二倍の文字列(* 2)と私は今、ベクトル/リストを使用するカント....のn \

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

が動作していない属性ごとに2回線を使用します.. –

+0

私は解決のために私のポストを編集しました – RvdK

関連する問題