943,565 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 4076
  • VB.NET RSS
Sep 6th, 2009
0

how to reset the form

Expand Post »
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?
Reputation Points: -1
Solved Threads: 23
Posting Whiz in Training
babbu is offline Offline
207 posts
since Jun 2009
Sep 6th, 2009
0

Re: how to reset the form

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:
vb Syntax (Toggle Plain Text)
  1. private sub ClearCtrl
  2. for each ctrl as control in Form1
  3. try
  4. if typeof(ctrl) is checkbox then ctrl.checked=false
  5. if typeof(ctrl) is textbox then ctrl.clear
  6. catch as exception
  7. 'catch the containers here
  8. end try
  9. next
end sub

something like that
Last edited by GeekByChoiCe; Sep 6th, 2009 at 2:27 am.
Featured Poster
Reputation Points: 208
Solved Threads: 168
Practically a Master Poster
GeekByChoiCe is offline Offline
692 posts
since Jun 2009
Sep 6th, 2009
0

Re: how to reset the form

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?

vb.net Syntax (Toggle Plain Text)
  1. For Each c As Control In Me.Controls
  2. If TypeOf c Is TextBox Then
  3. CType(c, TextBox).Text = String.Empty
  4. End If
  5. Next
Moderator
Reputation Points: 2136
Solved Threads: 1228
Posting Genius
adatapost is offline Offline
6,527 posts
since Oct 2008
Sep 6th, 2009
-1

Re: how to reset the form

oi sry i just saw i missed something
it should be "for each ctrl as control in Form1.controls"
Featured Poster
Reputation Points: 208
Solved Threads: 168
Practically a Master Poster
GeekByChoiCe is offline Offline
692 posts
since Jun 2009
Sep 6th, 2009
0

Re: how to reset the form

cant edit my post anymore. but since adatapost told me its not working i did a test and its working

vb Syntax (Toggle Plain Text)
  1. For Each ctrl As Control In Me.Controls
  2. Try
  3. If TypeOf (ctrl) Is CheckBox Then DirectCast(ctrl, CheckBox).Checked = False
  4. If TypeOf (ctrl) Is TextBox Then DirectCast(ctrl, TextBox).Clear()
  5. Catch ex As Exception
  6. 'catch the containers here
  7. End Try
  8. 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.
Featured Poster
Reputation Points: 208
Solved Threads: 168
Practically a Master Poster
GeekByChoiCe is offline Offline
692 posts
since Jun 2009
Sep 6th, 2009
0

Re: how to reset the form

@GeekByChoice : it should be "for each ctrl as control in Form1.controls".
-- It must be Me.Controls.
Moderator
Reputation Points: 2136
Solved Threads: 1228
Posting Genius
adatapost is offline Offline
6,527 posts
since Oct 2008
Sep 6th, 2009
0

Re: how to reset the form

yeye take it easy man. i was sure the user can figure that out by himself. but anyway u r right
Featured Poster
Reputation Points: 208
Solved Threads: 168
Practically a Master Poster
GeekByChoiCe is offline Offline
692 posts
since Jun 2009
Sep 6th, 2009
0

Re: how to reset the form

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
Reputation Points: 10
Solved Threads: 1
Light Poster
Arunabh Nag is offline Offline
40 posts
since Apr 2009
Sep 6th, 2009
0

Re: how to reset the form

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.
Featured Poster
Reputation Points: 1749
Solved Threads: 735
Senior Poster
sknake is offline Offline
3,948 posts
since Feb 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: How to pass a file name from another class
Next Thread in VB.NET Forum Timeline: Receive Email in vb.net 2005 Part 2





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC