views:

476

answers:

1

Hi Friends,
i want to display a new row in my listbox on my winform. I have a code like this on my backhand class.

 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

here return a string[] array will be returned to UI class which contains the code like this

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
            }

Example for xml file element

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

This displays attribute name and values like this in listbox in a single line:

Attribute Name:name , Attribute Value:John

But i want it to be displayed like this in listboxas :

Attribute Name : name

Attribute Value : John

Can you tell me where i m going wrong? Thanks for your help...

A: 

You can try adding a "\n" to the string

But you can also use a vector/list with string so you can prepend the name and value attribute in seperate lines

EDIT: This maybe better, reserve twice as much strings (*2) and use 2 lines for each attribute

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
PoweRoy
\n is not working....i cant use vector/list now..
crazy_itgal
I editted my post for a solution
PoweRoy