controls' Tag property

Ariez

Centurion
Joined
Feb 28, 2003
Messages
164
Does anyone have a concrete example of the tag use...?
i saw it was about linking data...more...
 
Let me put it this way.
what would be a common use of this prop.
It has to be more than an extra string holder. and what about data link?
 
I use the tag property whenever I want to add some extra information to a control but feel to lazy to program an extra new inherited class.

E.g. in our application we have control containers that can be prefilled and arranged with special controls at designtime and/or runtime. In order to clean up on a context switch I need to know, which controls where created at runtime, which were created at designtime. I do this by setting the .Tag in the contstructor

If not me.DesignTime Then me.Tag = "Created at Runtime"

In other cases I have used the tag (on listviewitems) to keep track of the last time that I updated their status (which could result in an icon change).

HTH
Heiko
 
well, that's interesting...
thats right Heiko, since now we can inherit and add any strongly typed property we like to any control, this tag seems a bit obsolete BUT may be a handy "extra string". Never used it myself but I see that I could have...

Anyways i saw somewhere the idea of dataset linking with the tag, it aroused my curiosity...if u guys have some insight on this eventually give it a thread...
thx for the input...

(Crescent and StCatherine...these were my college wonderyears tag!..I miss it.. gotta go back someday...with my wife this time!!!)
 
"with my wife this time!!!" Are you sure? :)

I just thought of something I used the tag for, it was a set of 12 radio buttons, each tag represented a value. I had one event handler for all the radios.

So a single line of code did what may have taken a large Select Case.
 
I think the tag is a holdover from VB6 but it can be used for whatever you find necessary. I've used it to hold objects in some rare circumstances. As Robby pointed out, you can now easily create a new class to add a few custom properties to controls.

I've put boolean values in a TabPage.Tag (to determine if it's ever been visited), for example...

-nerseus
 
Back
Top