Search code examples
code-behindext.nettreepanel

Set AttributesObject dynamically


If I set this for a treepanel item:

nodeItem.AttributesObject = new { c0 = 11111, c222 = 100000, c444 = 200000 };

everything is OK, but I need to set AttributesObject dynamically. I mean the columns are dynamic so I don't know the property names in compile time.

when I use this:

var propertyValues = new Dictionary<string, int>();
.....
nodeItem.AttributesObject = propertyValues;

It doesn't work. How can I do this?


Solution

  • You can use System.Reflection to create an object with dynamic properties.

    Or use a Node's CustomAttributes.

    Ext.Net.Node node = new Ext.Net.Node();
    
    node.CustomAttributes.Add(new ConfigItem("c0", "11111", ParameterMode.Raw));
    node.CustomAttributes.Add(new ConfigItem("c222", "100000", ParameterMode.Raw));