TreeNode sorting problem
-
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.
-
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.
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.