473,395 Members | 1,919 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.

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.TabControl
'???????????????
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 1603
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.TabControl
'???????????????
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
ControlCollection 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 ControlCollection)
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.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
disableControls(tab.Controls)
Next
End If
Next
End Sub
Notice that I changed the argument to the Sub to be a ControlCollection
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.Controls)

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
ControlCollection. So I ended up with two subs.

Public Sub disableControlControls(ByVal container As
Control.ControlCollection)
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)
disableControlControls(tmpPanel.Controls)
ElseIf TypeOf ctr Is TabControl Then
Dim tmpCtrl As TabControl = DirectCast(ctr, TabControl)
For Each tab As TabPage In tmpCtrl.Controls
disableControlControls(tab.Controls)
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)
disableControlControls(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)
disableControlControls(tmpPanel.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.Controls
disableControlControls(tab.Controls)
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
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...
7
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...
1
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...
5
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...
6
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
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...
4
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...
5
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: ...
4
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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...
0
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,...

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.