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.
Jason 5 49014
Hi Jason,
it is possible to clear all them at once but you will have to write
recursive function becaues some controls could be in subcontainers
you could use
public ClearConent(Con trol parent)
foreach(Control ctl in parent.Controls )
{
//clear contained controls
if (ctlControls.Co unt > 0) ClearConent(ctl );
if(ctl is Textbox) ((TextBox)ctl). Text = string.Empty;
elseif (ctl is CheckBox) ((CheckBox))ctl ).Checked = false;
}
Hope this help
Galin Iliev [MCSD.NET]
Hi Jason,
Try this loop:
private void button1_Click(o bject sender, EventArgs e)
{
foreach (Control c in this.Controls)
if (c is TextBox)
(c as TextBox).Clear( );
}
Regards - Octavio 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. Jason
Thanks!
How about some TextBoxes and ComboBoxes in a GoupBox?
"Galcho[MCSD.NET]" <ga****@gmail.c om>
???????:11***** *************** **@g49g2000cwa. googlegroups.co m... Hi Jason, it is possible to clear all them at once but you will have to write recursive function becaues some controls could be in subcontainers
you could use
public ClearConent(Con trol parent) foreach(Control ctl in parent.Controls ) { //clear contained controls if (ctlControls.Co unt > 0) ClearConent(ctl );
if(ctl is Textbox) ((TextBox)ctl). Text = string.Empty; elseif (ctl is CheckBox) ((CheckBox))ctl ).Checked = false;
}
Hope this help Galin Iliev [MCSD.NET]
Hi,
"Jason Huang" <Ja************ @hotmail.com> wrote in message
news:OB******** ******@TK2MSFTN GP12.phx.gbl... Thanks! How about some TextBoxes and ComboBoxes in a GoupBox?
It will work the same, also with Panel , and any other grouping control.
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Thanks Galcho!
What does this code "ctl.Controls.C ount > 0" mean?
"Galcho[MCSD.NET]" <ga****@gmail.c om>
???????:11***** *************** **@g49g2000cwa. googlegroups.co m... Hi Jason, it is possible to clear all them at once but you will have to write recursive function becaues some controls could be in subcontainers
you could use
public ClearConent(Con trol parent) foreach(Control ctl in parent.Controls ) { //clear contained controls if (ctlControls.Co unt > 0) ClearConent(ctl );
if(ctl is Textbox) ((TextBox)ctl). Text = string.Empty; elseif (ctl is CheckBox) ((CheckBox))ctl ).Checked = false;
}
Hope this help Galin Iliev [MCSD.NET] This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Dave |
last post by:
How do I check in a Windows Forms app if any controls have changed? I have
a form that collects data, and I want to prompt the user if they try to exit
the app, or load a new file, without saving changes that have been made.
In MFC/Win32, you'd trap the WM_COMMAND/EN_CHANGE notification messages,
etc. But, this doesn't seem to happen in Windows Forms. I tried Spy-ing a
windows forms app, and the WM_COMMAND messages don't even get sent...
|
by: Alison |
last post by:
Hi, Al
I am trying to design a user interface which provides both menus and toolbars for some users to click on whatever they want to do, at the same time, I would like to have a console window available in the same form for users to enter commands and display outputs if some prefer to use character based user interface. I would like to implement the user interface in vb .net. Now I have menus and toolbars ready, but do not now how to get a...
|
by: VictorT |
last post by:
Hi All,
I am trying to create a simple Windows form that lists a users' data
one user at a time with the usual "Next" & "Previous" buttons.
Upon loading the form, I am able to populate all textboxes however
when clicking either of the buttons, nothing happens - the data from
the next/previous rows does not re-populate the textboxes. This is an
extremely simple situation yet I cannot figure out what is going
wrong.
Can anyone help? I've...
|
by: Rob |
last post by:
Hi to all.
I am new to Visualbasic.net and windowz programming in general so I hope
someone can help.
I am trying to get info from a csv (Excell) file into a windows form.
For instance I want to get the totals of one "column" and put it into a
textbox on a form when I press a button. I did not think it would be
difficult to do , but I cant seem to get it right.
I have managed to get a datagrid working , using the oledbDataAdapter...
|
by: Rod Gill |
last post by:
Hi,
I have a form that when opened in the designer appears of the screen. The
form selector can't be dragged (or resized) and if I scroll right and down
to centralise it the form simply jumps further away, completely leaving the
selector box area.
Any ideas? VS 2003 and VB.Net
This is a simple application at the moment but the form is inherited from a
| |
by: newbie |
last post by:
Hi,
I have a windows form written in C#. The form has multiple textboxes
and multiple buttons.
I want to create a form where when the users clicks on a particulat
textbox and then clicks on a button, a text is added to that textbox.
How do i go about doing this when a user selects on any textbox and
clicks on a buttont to insert text, it insert the text in the correct
|
by: inpuarg |
last post by:
I have a windows form, there are button , textbox label etc. controls
on it. and i can programmatically get each of their names. and i also
have a printPreviewDialog on a form.
I cannot get it through loop.
i know that it does not have an appearance.
so - how can i get it programmatically ?
private void button1_Click(object sender, EventArgs e)
|
by: bsturg21 |
last post by:
Hello,
I have a windows form that has a series of linklabels on it, and I
need to have each linklabel, when clicked, open a separate windows
form that has a single paramter passed into it. The form that has the
System.Windows.Forms.LinkLabel controls on it is in a different
project and under a different namespace from the file where the
LinkLabel_LinkClicked events are, so I can't just do frm.ShowDialog
under the LinkClicked method. ...
|
by: =?Utf-8?B?VGFtbXkgTmVqYWRpYW4=?= |
last post by:
Hi, I am using Visual Studio C# windows. Every time I want to use some of the
methods in System.Windows.Form such as Clear(), it gives me error message and
saying "System.Windows.Forms.TextBox does not contain a definition for
'Clear'". Could someone help me with that. This happen for other methods that
are used in many places of the sources I am using but when I want to use them
it gives me error message.
Thanks
--
Nejadian
|
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: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
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.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |