473,785 Members | 2,396 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Still trying to disable controls

With the help of Cor Ligthert [MVP] in a pryor post I was able to make this
sub:

Public Sub disableControls (ByVal frm As Form)
'this is to create a read only form that has active buttons
Dim x As Long 'used for doing nothing
For Each ctr As Control In frm.Controls
If TypeOf ctr Is ComboBox Then
ctr.Enabled = False
ElseIf TypeOf ctr Is DateTimePicker Then
ctr.Enabled = False
ElseIf TypeOf ctr Is TextBox Then
ctr.Enabled = False
ElseIf TypeOf ctr Is GroupBox Then
ctr.Enabled = False
ElseIf TypeOf ctr Is Label Then
x = x
ElseIf TypeOf ctr Is Button Then
x = x
ElseIf TypeOf ctr Is TabControl Then
For Each tabctr As Control In System.Windows. Forms.TabContro l
'?????????????? ?
Next
End If
Next

This works great eccept for the TabControl. I need the TextBoxs, etc in the
TabControl disabled but not the Tabs or Buttons within the TabControl.
I can't seem to find the syntax I need to step through this collection (if
it is a collection). I will probably need the syntax to do the same with a
Group (which I was unable at first pass to do).

Thanks for the help. (A piece of code showing how would be Great!)
Rich
Sep 11 '06 #1
2 1625
RichG wrote:
With the help of Cor Ligthert [MVP] in a pryor post I was able to make this
sub:

Public Sub disableControls (ByVal frm As Form)
'this is to create a read only form that has active buttons
Dim x As Long 'used for doing nothing
For Each ctr As Control In frm.Controls
If TypeOf ctr Is ComboBox Then
ctr.Enabled = False
ElseIf TypeOf ctr Is DateTimePicker Then
ctr.Enabled = False
ElseIf TypeOf ctr Is TextBox Then
ctr.Enabled = False
ElseIf TypeOf ctr Is GroupBox Then
ctr.Enabled = False
ElseIf TypeOf ctr Is Label Then
x = x
ElseIf TypeOf ctr Is Button Then
x = x
ElseIf TypeOf ctr Is TabControl Then
For Each tabctr As Control In System.Windows. Forms.TabContro l
'?????????????? ?
Next
End If
Next

This works great eccept for the TabControl. I need the TextBoxs, etc in the
TabControl disabled but not the Tabs or Buttons within the TabControl.
I can't seem to find the syntax I need to step through this collection (if
it is a collection). I will probably need the syntax to do the same with a
Group (which I was unable at first pass to do).
You would do it the same way you would with a form. You would probably
be better off by creating a method that takes as it's parameter a
ControlCollecti on and then disables the controls. This sub can call
itself if the control is working on also has controls (such as a Panel
or TabPage):

Public Sub disableControls (ByVal container As ControlCollecti on)
For Each ctr As Control In container
If TypeOf ctr Is ComboBox Then
ctr.Enabled = False
ElseIf TypeOf ctr Is DateTimePicker Then
ctr.Enabled = False
ElseIf TypeOf ctr Is TextBox Then
ctr.Enabled = False
ElseIf TypeOf ctr Is GroupBox Then
ctr.Enabled = False
ElseIf TypeOf ctr Is Panel
'If we're dealing with a Panel, then pass its control
collection
'recursively back into this sub to process it's controls.
Dim tmpPanel As Panel = DirectCast(ctr, Panel)
disableControls (tmpPanel.Contr ols)
ElseIf TypeOf ctr Is TabControl Then
'If we're working with a TabControl, then we need to loop
through its
'tab pages to get at the controls on each page.
Dim tmpCtrl As TabControl = DirectCast(ctr, TabControl)
For Each tab As TabPage In tmpCtrl
disableControls (tab.Controls)
Next
End If
Next
End Sub
Notice that I changed the argument to the Sub to be a ControlCollecti on
since that what the Form controls collection is as well as a Panel and
TabPage. Notice that for a TabControl, I looped through the tab pages
and then passed it's control collection back into this sub. You could
call this from a button click by using this:

disableControls (MyForm.Control s)

Hope this helps

Chris

Sep 11 '06 #2
Chris
Thanks a bunch. I was not able to implement exactly as you described, but
this what I ended up with. I could not implement an undefined
ControlCollecti on. So I ended up with two subs.

Public Sub disableControlC ontrols(ByVal container As
Control.Control Collection)
For Each ctr As Control In container
If TypeOf ctr Is ComboBox Then
ctr.Enabled = False
ElseIf TypeOf ctr Is DateTimePicker Then
ctr.Enabled = False
ElseIf TypeOf ctr Is TextBox Then
ctr.Enabled = False
ElseIf TypeOf ctr Is GroupBox Then
ctr.Enabled = False
ElseIf TypeOf ctr Is Panel Then
Dim tmpPanel As Panel = DirectCast(ctr, Panel)
disableControlC ontrols(tmpPane l.Controls)
ElseIf TypeOf ctr Is TabControl Then
Dim tmpCtrl As TabControl = DirectCast(ctr, TabControl)
For Each tab As TabPage In tmpCtrl.Control s
disableControlC ontrols(tab.Con trols)
Next
End If
Next
End Sub

Public Sub disableControls (ByVal frm As Form)
'this is to create a read only form that has active buttons
Dim x As Long
For Each ctr As Control In frm.Controls
If TypeOf ctr Is ComboBox Then
ctr.Enabled = False
ElseIf TypeOf ctr Is DateTimePicker Then
ctr.Enabled = False
ElseIf TypeOf ctr Is TextBox Then
ctr.Enabled = False
ElseIf TypeOf ctr Is Label Then
x = x
ElseIf TypeOf ctr Is Button Then
x = x
ElseIf TypeOf ctr Is GroupBox Then
Dim tmpGrp As GroupBox = DirectCast(ctr, GroupBox)
disableControlC ontrols(tmpGrp. Controls)
ElseIf TypeOf ctr Is Panel Then
'If we're dealing with a Panel, then pass its control
collection
'recursively back into this sub to process it's controls.
Dim tmpPanel As Panel = DirectCast(ctr, Panel)
disableControlC ontrols(tmpPane l.Controls)
ElseIf TypeOf ctr Is TabControl Then
'If we're working with a TabControl, then we need to loop
through its
'tab pages to get at the controls on each page.
Dim tmpCtrl As TabControl = DirectCast(ctr, TabControl)
For Each tab As TabPage In tmpCtrl.Control s
disableControlC ontrols(tab.Con trols)
Next
End If
Next
End Sub

I don't understand this:
Dim tmpCtrl As TabControl = DirectCast(ctr, TabControl)
What is the purpose of the DirectCast?

Thanks, Rich
Sep 11 '06 #3

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

Similar topics

1
4067
by: Ravikanth[MVP] | last post by:
Hi Even though the Viewstate has been disabled, ASP.NET still uses about twenty bytes for Viewstate. Not only can you disable Viewstate at the page level, but you can also disable Viewstate at the control level. For example, the following code disables Viewstate for a ListBox control:
7
23103
by: Scott Emick | last post by:
How can I disable events for the controls on a form? I tried setting the form's enable property to false, but that doesn't stop events from firing on its controls. I need to temporarily disable a form and load values into controls without any events firing, then re-enable the form. -- Scott Emick Web Programmer
1
1789
by: Bob | last post by:
Does anyone know how to disable javascript in the new Netscape 8 -- for off line testing (like can be done readily with the current MSIE, Firefox or Opera browsers) ? When I try tools -> options -> site controls -> web features and check or uncheck the 'enable javascript' box, nothing changes -- it stays enabled. I've searched FAQs, archives and google about the issue, with no luck.
5
2298
by: Edwin Knoppert | last post by:
I have a div which holds controls. I'm looking for a way to disable all controls but *without* setting each control enable state. Same to style>display i'm looking for a disable method. Do i need a container control for this?
6
1519
by: | last post by:
hi, how to disable the controls in page? thanks For each myControl in Page.Controls 'want to disable myControl? Next
0
1806
by: Ahmad Jalil Qarshi | last post by:
Hi! I have a problem while developing some webpages.The Problem is that:- How We Can Disable The Controls Of One Web Form From Other Web Form In Asp.net? Explanation:- There Should Be Two Web Form,Web Form1.aspx and Web Form2.aspx,Now From Web Form1.aspx When I Click One Button (Disable), Then Web Form2.aspx Buttons
4
6631
by: Jon Slaughter | last post by:
Is there any method to temporarily disable focus changing?(I assume only method is tab or mouse?) This problem has been tieing me up for a while and nothing seems to work. The only thing that I *know* will work is to disable all tab stops on all controls. This brute force method doesn't seem like a good idea though. What I wanted to do was take control the control enter/leave and mouse enter/leave and "switch back" the focus when it is...
5
11280
by: masterej | last post by:
Developers, Is there any way to disable all checkboxes on a form? I have a form with 160 checkboxes and I want to be able to disable all of them. Is there a way I can do something like this: for (int i = 0; i < 160; i++) { string checkbox = "checkBox" + i.toString(); (Cast)checkbox.enabled = false;
4
1575
by: tshad | last post by:
I have a page that has about 20 textboxes and dropdowns that I want to disable until a button is pushed. I don't want them to be hidden which I can do with <div visible=false runat=serveror <asp:panel visible=false runat=server>. I want them to see the whole page but just disable all the controls on the bottom 3/4 of the page. I could do it by just doing each control one at a time but then if I add or take a control off the page I...
0
9481
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,...
0
10155
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 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...
1
10095
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,...
0
9954
tracyyun
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...
0
8979
agi2029
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...
1
7502
isladogs
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...
0
6741
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5513
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4054
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 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.