473,395 Members | 1,462 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Disabling Form Objects

I have to issues:

1) Does anyone know of a programmatic way I can disable all textboxes,
combo, listboxes, and buttons on a form?

2) What is the best practice for disabling multiple controls on a form.
Basically, I need to disable almost everything on a form and re-enable when
a particular task is complete. It seems like I duplicate the code over and
over in the code... then later when I add a new control, I invariably miss
something.....

Mar 23 '06 #1
2 2425
Two possibilities:

1. Write code that goes through all of the controls on a form
(recursively walking through the Control list, disabling controls).
This has the advantage that you can pass in controls that you don't
want disabled, and selectively avoid them:

public static void DisableAllControlsExcept(Form myForm, params
Control[] exceptions) ...

2. I've noticed that if you disable a container, such as a Panel, it
disables all controls inside the container, although I don't have time
to try it out right now. The only downside is that you can't make any
exceptions.

Mar 23 '06 #2
By the way, you could write that static method like this (untested code
follows):

public static ArrayList DisableAllControls(ContainerControl container,
params Control[] exceptions)
{
ArrayList disabledControls = new ArrayList();
foreach (Control c in container)
{
ContainerControl childContainer = c as ContainerControl;
if (childContainer != null)
{

disabledControls.AddRange(DisableAllControls(child Container,
exceptions));
}
else if (Array.IndexOf(exceptions, c) < 0 && c.Enabled)
{
c.Enabled = false;
disabledControls.Add(c);
}
}
return disabledControls;
}

then when you want to enable them again, you can just do:

foreach (Control c in disabledControls)
{
c.Enabled = true;
}

and any that were disabled before the original call to
DisableAllControls are left disabled.

Mar 23 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Fluffy Convict | last post by:
I have found a workaround to disable certain options in an option list: var p = document.forms.elements; p.selectedIndex=-1; This works perfectly in IE - the selectedIndex becomes unclickable....
6
by: Scott Phelps | last post by:
How can I make an input box (or other objects) disabled or greyed out and still have them submit in the form? Thanks
4
by: omidmottaghi | last post by:
I need to disable/enable form elements in my form. the code i was developed works fine in FF, but in IE, its behaviour is very strange!! in the form, we have a lot of checkboxes, all of them...
5
by: Lyn | last post by:
Hi, I hope someone can help. I have a main form which mostly fills the Access window. In the bottom half of this form I have a tab control to display various types of data related to the main...
1
by: keni | last post by:
One method of disabling Design View is to create an MDE database. Without going into details, this won't work in my situation. What I need is just a snippet of VBA code that will disable the...
1
by: Jason Galvin | last post by:
I would like to disable the auto-populating feature (remembers form element text between post-backs) when creating a .NET form. I have succeeded in disabling auto-populate by creating my controls...
2
by: mitzie | last post by:
Is it possible to enable and disable check box of active record using a continuous form? The problem with what I have done is if user entered multiple records, then clicked 1st option box, all...
11
by: shankwheat | last post by:
I have a function which passes text from txtdebt to debtsbox which works fine. However, I want to add code which examines the value of debtsbox and if any of the values the user entered contain the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
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...
0
Oralloy
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,...
0
jinu1996
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...
0
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.