Solved

How to reload the form

Posted on 2003-11-03
1
312 Views
Last Modified: 2010-04-16
Greetings,

I have a C# form which users will use it for searching. How to reload the form or clear the form value once the user try to search for another one.( I have only one button for searching)

Thanks in advance.

0
Comment
Question by:mrong
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 20

Accepted Solution

by:
TheAvenger earned 40 total points
ID: 9677018
Create a small method to clear the form items by resetting them to the initial values, then call this method at the end of the search.

This has one disadvantage - if you add a new control to the form, you will have to add a line of code in this method to reset it's value as well.

You can make a more general solution as well, but it will work for a limited kind of controls: at the end of the OnLoad method remember all controls' values and on reset put them back. It will work fine for simple controls. Here is an example:

// In the class members
private Hashtable values = new HashTable();
...
// At the end of the OnLoad event
foreach (Control ctrl in this.Controls) {
  if (ctrl is TextBox)
    values[ctrl] = ctrl.Text;
  else if (ctrl is DateTimePicker)
    values[ctrl] = ((DateTimePicker)ctrl).Value;
  else ....   // Add here the same code for every type of control you have on the form
}
...
// At the reset function (called at the end of the search)
foreach (Control ctrl in this.Controls) {
  object val = values[ctrl];
  if (val == null)
    continue;

  if (ctrl is TextBox)
    ctrl.Text = (string)val;
  else if (ctrl is DateTimePicker)
    ((DateTimePicker)ctrl).Value = (DateTime)val;
  else ....   // Add here the same code for every type of control you have on the form
}
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question