Forms Collections

vbnewbie.com

New member
Joined
Jan 27, 2005
Messages
2
Programming Experience
1-3
Is there away to check for any changes on all the controls on the form?

Example, say if I have a bunch of yes and no radio controls and I want to check if any of them had changed before exiting the form, so I can apply the changes.

I assumming this has to do with forms collections?

I write in all my options during load from an INI file. so when the user changed one or more controls I don't really want to code to check for each control to verify change. I would think there would be a way to pass in all you controls to say a functions to check for change and pass out a true or false if they changed or not.

hope this makes sense

Thanks,
vbnewbie
 

TPM

Well-known member
Joined
Dec 7, 2004
Messages
623
Location
CA
Programming Experience
3-5
You want to loop throught the form.controls. Do it like this:

VB.NET:
dim c as control
for each c in form.controls
if c typeof(checkbox) then '< This may need to be changed, I always forget how you check typeof
'check if it's changed
end if
next

TPM
 

TPM

Well-known member
Joined
Dec 7, 2004
Messages
623
Location
CA
Programming Experience
3-5
No problem mate. You could also use the tag if you only wanted to check certain ones.
 

Paszt

Staff member
Joined
Jun 3, 2004
Messages
1,500
Location
Raleigh, NC - USA
Programming Experience
Beginner
Also possible is:
If TypeOf c Is RadioButton Then
If c.GetType Is GetType(RadioButton) Then

Seems like more work to check if each value has changed then save it than to simply save all the values.

You could create a boolean variable (say bDirty) and set that to true when any of the radioButtons change value. Then, If bDirty then save changes.
 
Last edited:

TPM

Well-known member
Joined
Dec 7, 2004
Messages
623
Location
CA
Programming Experience
3-5
Paszt said:
Also possible is:
If TypeOf c Is RadioButton Then
If c.GetType Is GetType(RadioButton) Then

Seems like more work to check if each value has changed then save it than to simply save all the values.

You could create a boolean variable (say bDirty) and set that to true when any of the radioButtons change value. Then, If bDirty then save changes.

Ahh yes I thought I had put the typeof statement wrong, for some reason I I can never remember the order...

Well that would depend on where/how the data was being saved, that's why I said about using the tag as an update flag, it would make checking if it's changed relatively fast. (I guess my comment about using the tag wasn't clear, sorry I hadn't had my coffee :) )
 

Paszt

Staff member
Joined
Jun 3, 2004
Messages
1,500
Location
Raleigh, NC - USA
Programming Experience
Beginner
TPM said:
Well that would depend on where/how the data was being saved,
Agreed. If it were a database for instance. vbnewbie.com stated INI file so I assume it's local and textwriting is usually very fast. So I still beleive that checking to see if the value has changed then saving it is twice as much work as simply saving it :).

I'm an engineer, it's in my nature to be picky :).
 

taxes

Member
Joined
Feb 6, 2005
Messages
5
Programming Experience
10+
Hi,

Why not use the Tag property of a control? Set it to "NO" in design view: set it to "Yes" in the CheckChanged event of the radiobutton: then when you want to check for changes

Dim ctl As Control
For Each ctl in Me.Controls
If TypeOf ctl Is RadioButton and Ucase(ctl.Tag) = "YES" Then
MessageBox.Show(ctl.name & " Has Changed")
ctl.Tag = "NO"
End If
Next
 
Top Bottom