I want to clear all the Text Boxes on the Form. Is there any short
method to avoid clearing them one by one. 6 8381
No, there isn't. You will have to cycle through all the textboxes on
the form, and then clear the text out yourself. It should be easy enough to
do, given a ControlsCollect ion instance, you can use the "as" operator to
determine if the control is a TextBox or not (or, TextBoxBase). If it is,
then you can set the Text property to an empty string.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"RP" <rp*********@gm ail.comwrote in message
news:11******** **************@ j4g2000prf.goog legroups.com...
>I want to clear all the Text Boxes on the Form. Is there any short
method to avoid clearing them one by one.
Oh, I want that itself. Can you please illustrate on how to use
ControlCollecti on?
On Aug 15, 12:38 am, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guar d.caspershouse. comwrote:
No, there isn't. You will have to cycle through all the textboxes on
the form, and then clear the text out yourself. It should be easy enough to
do, given a ControlsCollect ion instance, you can use the "as" operator to
determine if the control is a TextBox or not (or, TextBoxBase). If it is,
then you can set the Text property to an empty string.
--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard .caspershouse.c om
static void ClearTextBoxes( Control.Control Collection controls)
{
// Cycle through the controls.
foreach (Control control in controls)
{
// The textbox.
TextBoxBase textBox = (control as TextBoxBase);
// If there is a textbox, then clear it.
if (textBox != null)
{
// Set the text to an empty string.
textBox.Text = "";
}
}
}
Note that this will clear RichTextBoxes as well. If you want to only
clear textboxes, then you need to change the "(control as TextBoxBase)"
statement to "(control as TextBox)".
Furthermore, if you have a need to clear composite controls, then you
will have to iterate through the controls collection of each control you
come across at the top level, and so on, and so on until there are no more
children.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"RP" <rp*********@gm ail.comwrote in message
news:11******** *************@i 38g2000prf.goog legroups.com...
Oh, I want that itself. Can you please illustrate on how to use
ControlCollecti on?
On Aug 15, 12:38 am, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guar d.caspershouse. comwrote:
> No, there isn't. You will have to cycle through all the textboxes on the form, and then clear the text out yourself. It should be easy enough to do, given a ControlsCollect ion instance, you can use the "as" operator to determine if the control is a TextBox or not (or, TextBoxBase). If it is, then you can set the Text property to an empty string.
-- - Nicholas Paldino [.NET/C# MVP] - m...@spam.guard .caspershouse.c om
How to call this function from say, ButtonClick()
On Aug 15, 12:57 am, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guar d.caspershouse. comwrote:
static void ClearTextBoxes( Control.Control Collection controls)
{
// Cycle through the controls.
foreach (Control control in controls)
{
// The textbox.
TextBoxBase textBox = (control as TextBoxBase);
// If there is a textbox, then clear it.
if (textBox != null)
{
// Set the text to an empty string.
textBox.Text = "";
}
}
}
On Aug 14, 4:05 pm, RP <rpk.gene...@gm ail.comwrote:
How to call this function from say, ButtonClick()
On Aug 15, 12:57 am, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guar d.caspershouse. comwrote:
static void ClearTextBoxes( Control.Control Collection controls)
{
// Cycle through the controls.
foreach (Control control in controls)
{
// The textbox.
TextBoxBase textBox = (control as TextBoxBase);
// If there is a textbox, then clear it.
if (textBox != null)
{
// Set the text to an empty string.
textBox.Text = "";
}
}
}- Hide quoted text -
- Show quoted text -
private void button1_Click(o bject sender, EventArgs e)
{
foreach (Control control in Controls)
{
if (control is TextBox)
{
TextBox textBox = control as TextBox;
textBox.Clear() ;
}
}
}
The last code is not enough, think on container within a container, so using
the simple control collection is not good, you should also check whether its
a container which also have its own private controls to delete (collection of
user controls).
--
Sincerely
Yaron Karni http://dotnetbible.blogspot.com/
"xt******@gmail .com" wrote:
On Aug 14, 4:05 pm, RP <rpk.gene...@gm ail.comwrote:
How to call this function from say, ButtonClick()
On Aug 15, 12:57 am, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guar d.caspershouse. comwrote:
static void ClearTextBoxes( Control.Control Collection controls)
{
// Cycle through the controls.
foreach (Control control in controls)
{
// The textbox.
TextBoxBase textBox = (control as TextBoxBase);
// If there is a textbox, then clear it.
if (textBox != null)
{
// Set the text to an empty string.
textBox.Text = "";
}
}
}- Hide quoted text -
- Show quoted text -
private void button1_Click(o bject sender, EventArgs e)
{
foreach (Control control in Controls)
{
if (control is TextBox)
{
TextBox textBox = control as TextBox;
textBox.Clear() ;
}
}
}
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: T. Wintershoven |
last post by:
Hello,
I have a few textboxes placed on a SSTab control devided over 3 tabs
Is there a way to clear all textboxes in one time in stead of one by one.
Someone told me "Use for each item in.........."
???????????
T.i.a.
|
by: Joe |
last post by:
I'm wondering how to loop through controls in VB.NET. I have the code from VB6 ok, but I can't figure out how to do it correctly in .NET. This is an example from my VB6 code that loops through controls in a specific frame on a form and unselects the option buttons. .NET barks at this line of code: thiscontrol.value = False
Private Sub UnSelectOpts(ByVal passedframeCaption As String)
Dim thiscontrol As Control
For Each thiscontrol In Me...
|
by: Thonglao Rud |
last post by:
I'm trying to clear all textbox on the form.
foreach (Control c in this.Controls)
{
//if (c.GetType() == typeof(TextBox))
if (c is TextBox)
{
// Found it
c.Text = "";
MessageBox.Show(c.Name.ToString());
|
by: nx-2000 |
last post by:
I've got a very large C# forms app and now that its being used in
bigger environments we're getting a steady stream of "why does it do
this?" problems. The most nagging of which right now is that when a
MessageBox.Show() is displayed, if the user hits enter or esc, those
keys get passed back to the form. From searching online, this is
apparently by design(for whom, I don't know, why its not optional, I
_really_ don't know). This...
|
by: Peter Afonin |
last post by:
Hello:
I need to clear all textboxes on the webform after the data has been
submitted. How can I do this in one step?
I found a C# code:
// get a reference to your form control
Control frm = FindControl("YourFormID");
foreach(Control ctrl in frm.Controls)
| |
by: jw56578 |
last post by:
When a page does a post back and there is data in a textbox, that
textbox will get automatically repopulated with that data due to the
posting of the form. Disabling viewstate has no affected on textbox
controls, so how do you make it so that the text box value is cleared
out on postback?
|
by: KKuser |
last post by:
Hello:
I have 20, 30 text and combo boxes on one form, and I would like to clear
them up at one time using the statement "With..........End With".
I used this when using VB6, but I don't know if I can use the same way in
VB.Net. If I can't use With statement in VB.Net, what should I do?
Thanks!!
|
by: Jason Huang |
last post by:
Hi,
In my C# Windows Form MyForm, it has many TextBoxes, e.g., txtName, txtID,
txtAddress, ...,
it also has many ComboBoxes, e.g., cboState, cboGender.
How do I clear all those controls's Text in a function? Is it possible to
do it in foreach loop?
Thanks for help.
|
by: Tom |
last post by:
I have a textbox on my web form were users can enter in 1 name or many names. The form then validates the name against the database.
If the name is valid its then saved into a varaible to be used at a later time. The issue I'm having is as follows:
the user enters in 2 names
John, Greg
clicks my valid button they're both valid so both names are stored in the variable so my variable looks like
John,Greg and both are in the textbox.
...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |