Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > VB.NET 2002/2003 Basics
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 22nd, 2005, 12:12 PM
Friend of Wrox
Points: 4,332, Level: 27
Points: 4,332, Level: 27 Points: 4,332, Level: 27 Points: 4,332, Level: 27
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default Resetting a form

Hello all,

   I have a form with a bunch of combo boxes and textboxes for data input. Once the user saves the entered info, I want to clear all the controls, basically set all the comboboxes to the original item, and clear all the textboxes. Is there a way to do this with out writing code, control by control? Possibly loop through a controls collection?

Thanks for the help.

Jim
Reply With Quote
  #2 (permalink)  
Old March 22nd, 2005, 05:45 PM
Friend of Wrox
 
Join Date: Nov 2004
Location: Port Orchard, WA, USA.
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

(“without” is 1 word...)

There was a method in MS Access to completely reset a form, but it does not appear that there is such a method in .NET.

Usually what I do is create a routine like 'Reset_frmMain()' which explicitly sets the values in all the controls.
It is more time consuming than a built in method, but it gives you complete control over what happens (you can skip some controls, set their values according to changing circumstances such as setting a time of day control, and so on).
Then, when necessary, just invoke that routine. (I know you know you can do this, as your question makes that clear. I'm not trying to imply you don't...)

But there certainly are times that a built in “clear ’em all!” method would be nice.

I wonder if there is a way to get the form to reload as if it were new?
Reply With Quote
  #3 (permalink)  
Old March 22nd, 2005, 05:52 PM
Friend of Wrox
Points: 4,332, Level: 27
Points: 4,332, Level: 27 Points: 4,332, Level: 27 Points: 4,332, Level: 27
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Thanks for the reply and spelling lesson :)

I did actually write me own function and excluded controls as necessary. I was wondering if there was a method like that. I come from a Power Builder background and that functionality exists.

I have called events explicitly in ASP.NET, but it can get messy and probably not a good idea but it can be done.
Reply With Quote
  #4 (permalink)  
Old March 22nd, 2005, 06:16 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , .
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
Default

You can use the controls collection to loop through all of the controls on a form (or panel, or groupbox, anything that can hold controls). If it is a textbox, radiobutton, checkbox, etc., do a type conversion and reset it how you want.

It isn't that difficult (I think the one that I wrote only has about 10 lines of code. The problem that I ran into was comboboxes and resetting them to a default value. If there is one or they all hold the same information, it isn't a problem. But if more than one needs reset with different info, it is a problem. I haven't had time to look into a way around this.

J
Reply With Quote
  #5 (permalink)  
Old March 22nd, 2005, 11:54 PM
Friend of Wrox
Points: 4,332, Level: 27
Points: 4,332, Level: 27 Points: 4,332, Level: 27 Points: 4,332, Level: 27
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

   They only way I have found around the combobox issue is to create a different data source for each one. I created a dataset and then used the copy method to create a copy for each combox.
Reply With Quote
  #6 (permalink)  
Old March 23rd, 2005, 12:54 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , .
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
Default

I don't have a problem populating the comboboxes, just resetting the selected value of multiple boxes when I clear all of the controls. If all you want to do is reset the combobox to index 0, it isn't a problem.

If you want to set the value to a specific item, say "California" in a combobox that contains states and "Wisconsin" in a different combobox that contains states my function won't work as written. It is something I hope to fix in the future, but like I said I haven't gotten around to it yet.

J
Reply With Quote
  #7 (permalink)  
Old March 23rd, 2005, 10:41 AM
Friend of Wrox
Points: 4,332, Level: 27
Points: 4,332, Level: 27 Points: 4,332, Level: 27 Points: 4,332, Level: 27
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

if you bind the comboboxes to the same data set you will have that problem. You either have to create a separate data set for each one, or loop through one dataset and add the items manually.

Reply With Quote
  #8 (permalink)  
Old March 23rd, 2005, 11:06 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , .
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
Default

I steer clear of binding the comboboxes. I have had too many issues when using this method.

J
Reply With Quote
  #9 (permalink)  
Old March 23rd, 2005, 11:37 AM
Friend of Wrox
Points: 4,332, Level: 27
Points: 4,332, Level: 27 Points: 4,332, Level: 27 Points: 4,332, Level: 27
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

   I agree with you and have learned my lesson. The behavior is different in ASP.NET. I am getting used to Windows application programming now.

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Close all MdiChield form from open one form/Button salman .NET Framework 2.0 6 December 10th, 2007 03:21 AM
Firefox Error when Form Floated / Form locks socoolbrewster CSS Cascading Style Sheets 5 October 6th, 2007 09:59 PM
How to refresh owner form on closing of child form akumarp2p C# 2005 0 December 22nd, 2006 10:27 AM
Resetting DIVs based on stacking order keithc BOOK: Beginning CSS: Cascading Style Sheets for Web Design ISBN: 978-0-7645-7642-3 1 March 6th, 2006 03:32 PM
Resetting Checkbox back to UNCHECKED savoym C# 3 July 21st, 2004 01:41 PM



All times are GMT -4. The time now is 06:29 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.