Solved

Fire an event with button to clear all the values in the controls on a winform application.

Posted on 2007-11-29
3
316 Views
Last Modified: 2012-06-22
I have 2 buttons one search for the values of all the controls(listbox,textbox,groupbox,datagridview) on a screen and the other should clear all the values when a user clicks on it and return the values when the user clicks again on Search button.

I have the code written for Search Button.But for the Clear button I embedded the code ,it is trying to clear the values but when the user tries to Search for new values by entering his firstname in a textbox.....its not pulling the details instead everything is blank..

What shoud be the code to clear values in a Datagrid view???


Here goes my sample try for clearing values:

Need help with the code!

private void button2_Click(object sender, EventArgs e)

        {

            ltemp1.Visible = false;

            ltemp.Visible = false;

            ClearAll();

        }
 

  private void ClearAll()

        {

            textBox1.Text = string.Empty;

            textBox2.Text = string.Empty;

            textBox3.Text = string.Empty;

            textBox4.Text = string.Empty;

       

            foreach (Control c in groupBox2.Controls)

            {

                c.Visible = true;

            }

            ltemp1.Visible = false;

            ltemp.Visible = false;

            groupBox2.Controls.Clear();
 

            foreach (Control c in groupBox3.Controls)

            {

                c.Visible = false;

            }
 

            ltemp.Text = "No Credit Card Stored";

            ltemp.Location = new Point(50, 50);
 

            groupBox3.Controls.Clear();

            ltemp.Visible = true;
 
 

            foreach (Control c in groupBox4.Controls)

            {

                c.Visible = true;

            }

            groupBox4.Controls.Clear();
 
 

            // lstSerListBox.Items.Clear();

            
 

        }

Open in new window

0
Comment
Question by:onebite2
  • 2
3 Comments
 
LVL 6

Expert Comment

by:Roopesh_7
ID: 20374622
gridview.datasource = null;
0
 

Author Comment

by:onebite2
ID: 20375234
Thanks a lot!This worked for a datagridview.

How about clearing the values in a list box which has datasource to it as

Listbox1.datasource=proreg;

Listbox1.items.clear();does not work as listbox has datasource to it...
listbox1.selecteditems.clear();also is not working..

I appreciate if u can tell me a work around for listbox too...
Thanks!
0
 
LVL 6

Accepted Solution

by:
Roopesh_7 earned 500 total points
ID: 20375349
ListBox1.Items.Clear()

ListBox1.Refresh
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

743 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now