0

hie
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?

5
Contributors
8
Replies
18
Views
7 Years
Discussion Span
Last Post by sknake
0

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

end sub

something like that

Edited by GeekByChoiCe: n/a

1

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
-1

oi sry i just saw i missed something
it should be "for each ctrl as control in Form1.controls"

Votes + Comments
No. It won't work.
0

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.

0

@GeekByChoice : it should be "for each ctrl as control in Form1.controls".
-- It must be Me.Controls.

0

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

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.