Solved

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

Posted on 2007-11-29
3
322 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
[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
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
"Emulate" TAB key when press Enter Key 3 92
using sqldatareader to populate cells in Excel-syntax 6 33
C# Formatting DateTime String Value 5 67
Coding for the first time 9 99
Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

739 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