set complex property on the fly

  • Thread starter Thread starter George Meng
  • Start date Start date
G

George Meng

Hi folks,



I have a Treeview control in the Winform, and I want to change the text of
the 5th node base on an expression:



dim sObject as string = "Treeview1.Node.Items(5).Text"

dim sValue as string = "New Text for the node"



How can I make this happen by using reflection or any other way?



Basically, my question is how I can make change to a complex property:

Object.Property.property



Thanks for any ideas.



George
 
You'll need to:
(1) parse your expression string, then use the System.Reflection API to get
the values of each sub-property in turn.
or
(2) Comple the expression and load the resulting assembly (requires compiler
installed)
or
(3) Choose a scripting language that can handle your expression, and ask it
to evaluate your expression. (Try IronPython- that should work for you.)

m
 
Mike said:
You'll need to:
(1) parse your expression string, then use the System.Reflection API to
get the values of each sub-property in turn.
or
(2) Comple the expression and load the resulting assembly (requires
compiler installed)

or
(2a) Parse your expression string, and use Reflection.Emit to generate code
on the fly, and load the assembly. (I didn't mention this before, as it's
the hardest and probably won't by you much over (1) unless you call the same
expression over and over many times
 
Thanks Mike, your suggestions are very helpful. I prefer to use reflection
to do it.
I will try.
 
Back
Top