if the user, after working with the form wishes to reset it, how can it be done.
will me.refresh() help.
wht is it used for?
no. me.refresh will just update
its actually depends on what exactlly you wish to reset like textboxes, checkboxes and so on.
you could do an function like:
private sub ClearCtrl for each ctrl as control in Form1 try if typeof(ctrl) is checkbox then ctrl.checked=false if typeof(ctrl) is textbox then ctrl.clear catch as exception 'catch the containers here end try next
something like that
I don't get a word "reset". Do you want to reset the state of controls or just clear the text or setting up selectedindex with 0?
For Each c As Control In Me.Controls If TypeOf c Is TextBox Then CType(c, TextBox).Text = String.Empty End If Next
oi sry i just saw i missed something
it should be "for each ctrl as control in Form1.controls"
cant edit my post anymore. but since adatapost told me its not working i did a test and its working
For Each ctrl As Control In Me.Controls Try If TypeOf (ctrl) Is CheckBox Then DirectCast(ctrl, CheckBox).Checked = False If TypeOf (ctrl) Is TextBox Then DirectCast(ctrl, TextBox).Clear() Catch ex As Exception 'catch the containers here End Try Next
works as it is and only if you dont have the controls inside containers such as panels, groupboxes then you need to recurse these aswell.
@GeekByChoice : it should be "for each ctrl as control in Form1.controls".
-- It must be Me.Controls.
yeye take it easy man. i was sure the user can figure that out by himself. but anyway u r right ;)
isn't there a centralised option for resetting the from...
like am using a user specified array of custom controls on a flow panel connecting to a database.
Now how do i reset the data to it's initial state if the user presses a button called reset
Dispose the form and re-instantiate it to the state defined by the contructor(s). However I am almost certain this is not what you want so please clarify what you are doing, and what you would like to do.