Extended Properties

  • Thread starter Thread starter VJ
  • Start date Start date
V

VJ

I have a few controls that I am adding at Run-time to my Windows Forms... I
set the controls Name, Value.. etc to the appropriate properties for the
control. Apart from these I want to associate a bunch of values to the
control, that don't have a corresponding property. How do I store these with
control..

Thanks
VJ
 
VJ,
The short (cut) method would be to put a HashTable in the Tag property of
the control that you create. I say short cut as the Tag property is an
Object & the HashTable holds objects, so you need to do some interesting
casting to get values in & out & values could easily be trashed by other
code.

A (slightly) better method you could define a class that holds that holds
you associated values, then place an instance of this class in the Tag
property. This is better as you're not dealing with the HashTable.

I would derive a derive a new class from each control that I am using,
adding a type safe property for each associated value or a single type safe
property holding an Associated values class. More then likely I would use
the Associated values class...

Hope this helps
Jay
 
Back
Top