rasingh24 0 Newbie Poster

Hi,
i have a small project in which on selecting a node in treeview displays attributes in listbox.In treeView1_AfterSelect, the text parsing code depends on the textual representation for a node in the tree view, which can be changed at any time and break the entire logic of list display. This strong dependency between the tree view and the list display should be eliminated by binding nodes in the treeview to nodes of the XML document, so that the raw Xml data can be used to display text in the list.What should i write here?

private void treeView1_AfterSelect(object sender,TreeViewEventArgs e)  
        {  
            listBox1.Items.Clear();  
            TreeNode treenode = e.Node;   //Node selected in Treeview            
            String text = treenode.Text;  
            String relevent = text;  
            Boolean flag = true;  
            while (flag)  
            {  
                int SpaceIndex = relevent.IndexOf(" ");  
                if (SpaceIndex != -1)  
                {  
                    int indexofEqual = relevent.IndexOf('=', SpaceIndex);  
                    if (indexofEqual != -1)  
                    {  
                        int indexOFValue = relevent.IndexOf("\"", indexofEqual + 2);  
                        if (indexOFValue != -1)  
                        {  
                            String attribute = relevent.Substring(SpaceIndex + 1, indexofEqual - SpaceIndex - 1);   //starts displaying the attribute name after space for the given length  
                            String value = relevent.Substring(indexofEqual + 2, indexOFValue - indexofEqual - 2);   //starts displaying the attribute value after  "="sign for the given length  
                            listBox1.Items.Add("Attribute : " + attribute + "   Value : " + value);                 // add it in the list box
                            relevent = relevent.Substring(indexOFValue);
                        }
                        else
                        {
                            listBox1.Items.Add("Bad format of the xml file for this node");
                            flag = false;
                        }
                    }
                    else
                    {
                        flag = false;
                    }
                }
                else
                {
                    flag = false;
                }
            }
        }//AfterSelect()

Thanks in advance..