Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. TreeNode sorting problem

TreeNode sorting problem

Scheduled Pinned Locked Moved C#
helpquestionalgorithmstutorialworkspace
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    Zaegra
    wrote on last edited by
    #1

    I don't know if you know the GEDCOM file format (.ged, genealogy file standard[^]), but I'm trying to read one and I want to put it in a listview. The following code opens a gedcom file, and saves the data (per person) to a treeview.

    StreamReader reader = new StreamReader(@"test.ged");
    string[] lines;
    string file_content = reader.ReadToEnd();
    lines = file_content.Split(Environment.NewLine.ToCharArray()[0]);
    this.Text = lines.Length.ToString();

            TreeNode currentperson = new TreeNode();
            foreach(string line in lines)
            {
                string newline = line.Replace("\\n", "");
                newline = newline.Replace("\\r", "");
    
                try
                {
                    if (newline\[0\].ToString() == "0")
                    {
                        //MessageBox.Show("newperson wotwot!");
                        newline = newline.Replace("@", "");
                        newline = newline.Replace("0", "");
                        newline = newline.Replace("INDI", "");
                        TreeNode newperson = new TreeNode(newline);
                        gedcomtree.Nodes.Add(newperson);
                        currentperson = newperson;
                    }
                    else
                    {
                        TreeNode currentnode = new TreeNode(newline);
                        currentperson.Nodes.Add(currentnode);
                    }
                }
                catch { }
            }
    

    Now my question is: How can i sort the elements in a persons' node aswell? Example: 1 BIRT 2 DATE 01 FEB 1750 2 PLAC EDINBURGH 3 NOTE Old place. 1 DEAT 2 DATE 02 FEB 1800 etc. Should make: - BIRT -- DATE 01 FEB 1750 -- PLAC EDINGBURGH --- NOTE Old place. - DEAT -- DATE 02 FEB 1800 (In a treeview) Could someone help me out on this one? Im trying to get this to work for 3 days now, and i'm still stuck :sigh: Thanks in advance, Zaegra

    Motivation is the key to software development.

    D 1 Reply Last reply
    0
    • Z Zaegra

      I don't know if you know the GEDCOM file format (.ged, genealogy file standard[^]), but I'm trying to read one and I want to put it in a listview. The following code opens a gedcom file, and saves the data (per person) to a treeview.

      StreamReader reader = new StreamReader(@"test.ged");
      string[] lines;
      string file_content = reader.ReadToEnd();
      lines = file_content.Split(Environment.NewLine.ToCharArray()[0]);
      this.Text = lines.Length.ToString();

              TreeNode currentperson = new TreeNode();
              foreach(string line in lines)
              {
                  string newline = line.Replace("\\n", "");
                  newline = newline.Replace("\\r", "");
      
                  try
                  {
                      if (newline\[0\].ToString() == "0")
                      {
                          //MessageBox.Show("newperson wotwot!");
                          newline = newline.Replace("@", "");
                          newline = newline.Replace("0", "");
                          newline = newline.Replace("INDI", "");
                          TreeNode newperson = new TreeNode(newline);
                          gedcomtree.Nodes.Add(newperson);
                          currentperson = newperson;
                      }
                      else
                      {
                          TreeNode currentnode = new TreeNode(newline);
                          currentperson.Nodes.Add(currentnode);
                      }
                  }
                  catch { }
              }
      

      Now my question is: How can i sort the elements in a persons' node aswell? Example: 1 BIRT 2 DATE 01 FEB 1750 2 PLAC EDINBURGH 3 NOTE Old place. 1 DEAT 2 DATE 02 FEB 1800 etc. Should make: - BIRT -- DATE 01 FEB 1750 -- PLAC EDINGBURGH --- NOTE Old place. - DEAT -- DATE 02 FEB 1800 (In a treeview) Could someone help me out on this one? Im trying to get this to work for 3 days now, and i'm still stuck :sigh: Thanks in advance, Zaegra

      Motivation is the key to software development.

      D Offline
      D Offline
      Dan Mos
      wrote on last edited by
      #2

      Zaegra wrote:

      string newline = line.Replace("\n", ""); newline = newline.Replace("\r", ""); try { if (newline[0].ToString() == "0") { //MessageBox.Show("newperson wotwot!"); newline = newline.Replace("@", ""); newline = newline.Replace("0", ""); newline = newline.Replace("INDI", ""); TreeNode newperson = new TreeNode(newline); gedcomtree.Nodes.Add(newperson); currentperson = newperson;

      One easy way will be to move all the newline.Replace(); in a separte loop, sort the array of strings, and then add the Nodes from the sorted array.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups