"Tag" Property not Sticking

Avi*

New member
Joined
May 9, 2007
Messages
3
Programming Experience
Beginner
so... this is the problem i'm having. i'm trying to use the "tag" property of controls to store help information about the specific control, and it seems to be working during debug, until i close the form, at which point it looses the information that was put into the tag. when i open the form back up, the "tag" property is blank again.
 
when you close the form and open the form again, it sounds like you're making a new instance of the form when you open it again, because this is a new instance it doesn't know about the other one (the one that was closed, which cannot be retrieved again)

which means you either need to hide the form instead of actually closing it and when you reopen the form simply show it instead of making a new instance

I cant help you further without knowing how you're handling the opening/closing (showing/hiding) the form(s)
 
Tags

I screwed up, and thought that the "tag" property could be permanently modified by the program -or- the program could change it's own source code. each time it opened, it created a new instance of itself, and since it cant change the source, it would just leave the tag empty.

yeah, rookie mistake

Avi*
 
to have the effect of a program "remembering things" like your tag property, when the program is exited simply save the data that's in the tag property to a file then when you run the program, if the file exists read the value(s) and set the tag property based on the value(s) read from the text file

if the file does not exist, here's where you set a default (or leave it blank)
 
There's also the Application Settings if you are using the Application Framework in V2. You can access it via the Properties Explorer under the (Application Settings) entry.
 
I screwed up, and thought that the "tag" property could be permanently modified by the program -or- the program could change it's own source code.
.NET programs cannot change their own source code, not in the classic "self modifying code" sense at least

If you set yout .tag properties in the form's constructor, or in the designer, they will not be blank
 
to have the effect of a program "remembering things" like your tag property, when the program is exited simply save the data that's in the tag property to a file then when you run the program, if the file exists read the value(s) and set the tag property based on the value(s) read from the text file

if the file does not exist, here's where you set a default (or leave it blank)

It should be possible to bind the .Tag property to an application setting, like Paszt hints at
 
Since the application I'm working on has about 60 forms or so, it wouldn't really be worth the time to go in and create a .txt file for each form, or just one if I was willing to mark all of the (200+) controls with a unique identifier. However working off of that idea, since the program already calls from an sql database anyway, I'll just create a table that stores all of the forms/controls/helpinfo, so it can use the form name and control name as lookups.

thanks for your help guys

Avi*
 
There's also the Application Settings if you are using the Application Framework in V2. You can access it via the Properties Explorer under the (Application Settings) entry.

It should be possible to bind the .Tag property to an application setting, like Paszt hints at

That's what I was already hinting to in the first place

Since the application I'm working on has about 60 forms or so, it wouldn't really be worth the time to go in and create a .txt file for each form, or just one if I was willing to mark all of the (200+) controls with a unique identifier. However working off of that idea, since the program already calls from an sql database anyway, I'll just create a table that stores all of the forms/controls/helpinfo, so it can use the form name and control name as lookups.

thanks for your help guys

Avi*

This sounds like a very good idea
 
Since the application I'm working on has about 60 forms or so, it wouldn't really be worth the time to go in and create a .txt file for each form, or just one if I was willing to mark all of the (200+) controls with a unique identifier. However working off of that idea, since the program already calls from an sql database anyway, I'll just create a table that stores all of the forms/controls/helpinfo, so it can use the form name and control name as lookups.

thanks for your help guys

Avi*

VB.NET:
For Each f As Form in My.Forms
  For Each c As Control in f.Controls
    If TypeOf c Is TextBoxBase Then DataBase.SaveString(DirectCast(c, TextBoxBase).Text)
    If TypeOf c Is ComboBox Then DataBase.SaveInteger(DirectCast(c, ComboBox).SelectedIndex)
    If TypeOf c Is DateTimePicker Then DataBase.SaveDate(DirectCast(c, TextBoxBase).Value)
  Next c
Next f

Similarly for restoring, write a routine that pulls the value back - if its null then maybe it was never saved, so dont set it :)

DataBase is a class youll have to write yourself. It could be a tableadapter with a few custom queries..
 
Back
Top