Click here to Skip to main content
15,891,597 members
Home / Discussions / C#
   

C#

 
GeneralRe: IPAddress range Pin
leppie1-Mar-03 6:27
leppie1-Mar-03 6:27 
Generalputting an img... Pin
sacoskun1-Mar-03 1:47
sacoskun1-Mar-03 1:47 
GeneralRe: putting an img... Pin
leppie1-Mar-03 6:17
leppie1-Mar-03 6:17 
GeneralButton events gets deleted! Pin
mirano1-Mar-03 1:35
mirano1-Mar-03 1:35 
GeneralRe: Button events gets deleted! Pin
James T. Johnson1-Mar-03 1:46
James T. Johnson1-Mar-03 1:46 
GeneralRe: Button events gets deleted! Pin
JProd1-Mar-03 18:42
JProd1-Mar-03 18:42 
GeneralAgain : How to save the TreeView Pin
j-hannemann28-Feb-03 22:35
j-hannemann28-Feb-03 22:35 
GeneralRe: Again : How to save the TreeView Pin
leppie28-Feb-03 23:20
leppie28-Feb-03 23:20 
j-hannemann wrote:
Now I tried the Save and Load routines from the DUMeter project !
They're very good ..


Thanks, but that will only work for flat classes. It was never intended to walk a tree. Here's some code that mite help, but I have not made a FromXml function.
public class HashTree: System.Collections.DictionaryBase
{
   char del;
   
   public HashTree()
   {
      del = (char) 0;
   }

   public HashTree(char delimter)
   {
      del = delimter;
   }

   internal int level = 0;

   private HashTree(int level, char del):this(del)
   {
      this.level = level;
   }

   public virtual HashTree this[string key]
   {
      get
      {
         string[] tokens = key.Split(del);
         HashTree outer = this;
         foreach (string keyt in tokens)
         {
            if (!outer.Dictionary.Contains(keyt))
               outer.Dictionary.Add(keyt, new HashTree(outer.level + 1, del));
            outer = outer.Dictionary[keyt] as HashTree;
         }
         return outer;
      }
   }

   public virtual System.Collections.ICollection Keys
   {
      get
      {
         return this.Dictionary.Keys;
      }
   }

   public virtual System.Collections.ICollection Values
   {
      get
      {
         return this.Dictionary.Values;
      }
   }

   private object obj;

   public object Value 
   {
      get {return obj;}
      set {obj = value;}
   }

   public string ToXml()
   {
      StringBuilder output = new StringBuilder();

      string pad = "";
      for (int i = 0; i < level; i++)
         pad += "\t";

      foreach (string key in Keys)
         output.AppendFormat("{2}<{0}>\n{1}{2}</{0}>\n",
            key, (this[key].Count > 0 ? this[key].ToXml() : (pad + "\t" + this[key].Value + "\n")), pad);
      return output.ToString();
   }
}
And the usage is easy.
HashTree tree = new HashTree('.');

foreach(....)
{
  tree
    ["rootlevel"]
      ["nextlevel"]
        ["anotherlevel"]
          .Value = "somevalue"; //dont you love funky usage?
  //or the same thing
  tree["rootlevel.nextlevel.anotherlevel"].Value = "somevalue";
}

string xml = tree.ToXml();
This give you a nice tree, but I havent got around to making a load from XML method. If you can make one, I'll give you credit Poke tongue | ;-P .

Cheers Smile | :)

I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
GeneralRe: Again : How to save the TreeView Pin
j-hannemann2-Mar-03 10:29
j-hannemann2-Mar-03 10:29 
GeneralUnmanaged Callback Pin
leppie28-Feb-03 11:43
leppie28-Feb-03 11:43 
GeneralRe: Unmanaged Callback Pin
Stephane Rodriguez.28-Feb-03 20:05
Stephane Rodriguez.28-Feb-03 20:05 
GeneralRe: Unmanaged Callback Pin
leppie28-Feb-03 22:11
leppie28-Feb-03 22:11 
GeneralRe: Unmanaged Callback Pin
Stephane Rodriguez.28-Feb-03 22:29
Stephane Rodriguez.28-Feb-03 22:29 
GeneralRe: Unmanaged Callback Pin
leppie28-Feb-03 22:48
leppie28-Feb-03 22:48 
GeneralRe: Unmanaged Callback Pin
leppie1-Mar-03 6:44
leppie1-Mar-03 6:44 
GeneralRe: Unmanaged Callback Pin
Stephane Rodriguez.1-Mar-03 10:46
Stephane Rodriguez.1-Mar-03 10:46 
GeneralRe: Unmanaged Callback Pin
leppie1-Mar-03 11:26
leppie1-Mar-03 11:26 
GeneralRegular Expression question Pin
chronobyte28-Feb-03 10:38
chronobyte28-Feb-03 10:38 
GeneralRe: Regular Expression question Pin
Daniel Turini28-Feb-03 11:11
Daniel Turini28-Feb-03 11:11 
GeneralRe: Regular Expression question Pin
chronobyte1-Mar-03 7:14
chronobyte1-Mar-03 7:14 
GeneralRe: Regular Expression question Pin
Domenic Denicola1-Mar-03 11:17
Domenic Denicola1-Mar-03 11:17 
GeneralRe: Regular Expression question Pin
Daniel Turini2-Mar-03 2:47
Daniel Turini2-Mar-03 2:47 
GeneralSaving Treeview/Listview selections Pin
vlusardi28-Feb-03 10:06
vlusardi28-Feb-03 10:06 
GeneralRe: Saving Treeview/Listview selections Pin
Stephane Rodriguez.28-Feb-03 20:22
Stephane Rodriguez.28-Feb-03 20:22 
GeneralAdding MDAC and .net framework redistribution to an application. Pin
Anonymous28-Feb-03 9:58
Anonymous28-Feb-03 9:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.