Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 22nd, 2005, 12:12 PM
Friend of Wrox
 
Join Date: Nov 2003
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
 
Old March 22nd, 2005, 05:45 PM
Friend of Wrox
 
Join Date: Nov 2004
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?
 
Old March 22nd, 2005, 05:52 PM
Friend of Wrox
 
Join Date: Nov 2003
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.
 
Old March 22nd, 2005, 06:16 PM
Friend of Wrox
 
Join Date: Jun 2003
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
 
Old March 22nd, 2005, 11:54 PM
Friend of Wrox
 
Join Date: Nov 2003
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.
 
Old March 23rd, 2005, 12:54 AM
Friend of Wrox
 
Join Date: Jun 2003
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
 
Old March 23rd, 2005, 10:41 AM
Friend of Wrox
 
Join Date: Nov 2003
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.

 
Old March 23rd, 2005, 11:06 AM
Friend of Wrox
 
Join Date: Jun 2003
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
 
Old March 23rd, 2005, 11:37 AM
Friend of Wrox
 
Join Date: Nov 2003
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.






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





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