tree view , list view relation ship, master detail relation ship

Hi guys,,


Im working on an application that retrieves data from an xml fiile to my form using tree view and list view controls...

I wrote the code to populate the employee code in the treeview control and it worked fine
then I wrote the code to retrieve the selected employee's data ,that I selected through my treeview,to the list view control
I will write down the code here so that u can help me debugging the code to know where the problem is...

here is my code

code to populate the treeview


protected void populateTreeView()
{
  statusBar1.Text =" Refreshing Employees Codes, Please Wait...";
  this.Cursor =  Cursors.WaitCursor;
  treeView1.Nodes.Clear();
  tvRootNode = new TreeNode("Employees Code");
  this.Cursor = Cursors.Default;
  treeView1.Nodes.Add(tvRootNode);
  TreeNodeCollection nodeCollect = tvRootNode.Nodes;
  string val ="";
  XmlTextReader reader = new XmlTextReader(@"C:\EmpRec.xml");
  reader.MoveToElement();
  try

  {
   while ( reader.Read())
   {
    if ( reader.HasAttributes && reader.NodeType == XmlNodeType.Element)
    {
     reader.MoveToElement();
     reader.MoveToElement();
     reader.MoveToAttribute("Id");
     val=reader.Value;
     reader.Read();
     reader.Read();
     if(reader.Name == "Dept.")
     {
      reader.Read();
     }
     TreeNode EcodeNode = new TreeNode(val);
     nodeCollect.Add(EcodeNode);
    

    }
    statusBarPanel1.Text = " Click on Employee Code to see the record";
   }
  }
  catch ( XmlException e)
  {
   MessageBox.Show( " Exception : "+ e.Message);
  }
}

then the code to 
initiate the listview and populate its columns

protected void initializeListControl()
{

  listView1.Clear();
  listView1.Columns.Add("Employee Name ",255,HorizontalAlignment.Left);
  listView1.Columns.Add("Date Of Join ",70,HorizontalAlignment.Right);
  listView1.Columns.Add("Grade",105,HorizontalAlignment.Left);
  listView1.Columns.Add("Salary ",105,HorizontalAlignment.Left);

}




then code to fill the listview with details of choosen employee code




protected void populateListView(TreeNode currNode)
{
  initializeListControl();
  XmlTextReader listViewReader = new XmlTextReader(@"C:\Documents and Settings\Administrator.MOSAAD\My Documents\Visual Studio Projects\Employee Records App\EmpRec.xml");
  listViewReader.MoveToElement();
  while ( listViewReader.Read())
  {
   string nodeName;
   string nodePath;
   string name;
   string dateOfJoin;
   string grade;
   string salary;
   string [] itemsArray = new string[4];
   listViewReader.MoveToFirstAttribute();
   nodeName =  listViewReader.Value;
   nodePath = currNode.FullPath.Remove(0,17);
   if ( nodePath == nodeName)
   {
    ListViewItem lvi;
    listViewReader.MoveToNextAttribute();
    name = listViewReader.Value;
    lvi = listView1.Items.Add(name);
    listViewReader.Read();
    listViewReader.Read();
    listViewReader.MoveToFirstAttribute();
    dateOfJoin = listViewReader.Value;
    lvi.SubItems.Add(dateOfJoin);
    listViewReader.MoveToNextAttribute();
    grade = listViewReader.Value;
    lvi.SubItems.Add(grade);
    listViewReader.MoveToNextAttribute();
    salary = listViewReader.Value;
    lvi.SubItems.Add(salary);
    listViewReader.MoveToNextAttribute();
    listViewReader.MoveToElement();
    listViewReader.ReadString();
    

   }

  }
}


then I added this code to the treeview after select event


private void treeView1_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
{
   TreeNode currNode = e.Node;
  if ( tvRootNode == currNode)
  {
   initializeListControl();
   statusBarPanel1.Text = " Double Click Employee Records .. ";
   return;
  }
  else 
  {
   statusBarPanel1.Text = " Click Employee code to view Individual Record ...";

  }
  populateListView(currNode);
  

}


then at last I added this code to the page_load event

private void EmployeeRecordsForm_Load(object sender, System.EventArgs e)
{
  populateTreeView();
  initializeListControl();
  
}


I dont know why when I choose an employee code in treeview it doesnt populate the employee's data in the listview control!!


Answer this question

tree view , list view relation ship, master detail relation ship

  • tree view , list view relation ship, master detail relation ship