473,804 Members | 3,190 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Locking controls in a form object

I want to lock all controls except the buttons on a form. I sometimes need
the form to call lockForms(Me).

public sub lockControls(fr m as form)
for each ctrl as control in frm
if left(ctrl.name, 3)<>"btn" then
ctrl.locked=tru e
endif
next
end sub

Unfortunitly "ctrl.locked=tr ue" is not valid in .net 2.0.
Is there an equivalent method in 2.0 for this?

Thanks
Aug 28 '06 #1
7 1395
I'm sorry, I need the first line to read:
"I sometimes want to call lockControls(Me )"
Thanks

"RichG" wrote:
I want to lock all controls except the buttons on a form. I sometimes need
the form to call lockForms(Me).

public sub lockControls(fr m as form)
for each ctrl as control in frm
if left(ctrl.name, 3)<>"btn" then
ctrl.locked=tru e
endif
next
end sub

Unfortunitly "ctrl.locked=tr ue" is not valid in .net 2.0.
Is there an equivalent method in 2.0 for this?

Thanks
Aug 28 '06 #2
Rich,

Not really those who are accessible you can enable and dispable and some you
can prevent to edit.

The normal way to see if something is a button is by the way.

If typeof ctr Is Button then

I hope this gives some help,

Cor

"RichG" <Ri***@discussi ons.microsoft.c omschreef in bericht
news:4C******** *************** ***********@mic rosoft.com...
>I want to lock all controls except the buttons on a form. I sometimes need
the form to call lockForms(Me).

public sub lockControls(fr m as form)
for each ctrl as control in frm
if left(ctrl.name, 3)<>"btn" then
ctrl.locked=tru e
endif
next
end sub

Unfortunitly "ctrl.locked=tr ue" is not valid in .net 2.0.
Is there an equivalent method in 2.0 for this?

Thanks

Aug 29 '06 #3
Hi, thanks for the response
Not really those who are accessible you can enable and dispable and some you
can prevent to edit.
I can't find "noedit" and "enabled" doe not work.
If typeof ctr Is Button then
Yes, that's a better way.. Thanks. I did not think about using "typeof". I
just have a consistant way of naming controls.

It's strange that this capability which I used so much in a previous version
of VB is not available here. I only occasionally need to dynamically "lock"
a control, but it is handy.
In this case I'm trying to make a form for "View" only, so that some people
can look at the values but cannot change them.
Rich
"Cor Ligthert [MVP]" wrote:
Rich,

Not really those who are accessible you can enable and dispable and some you
can prevent to edit.

The normal way to see if something is a button is by the way.

If typeof ctr Is Button then

I hope this gives some help,

Cor

"RichG" <Ri***@discussi ons.microsoft.c omschreef in bericht
news:4C******** *************** ***********@mic rosoft.com...
I want to lock all controls except the buttons on a form. I sometimes need
the form to call lockForms(Me).

public sub lockControls(fr m as form)
for each ctrl as control in frm
if left(ctrl.name, 3)<>"btn" then
ctrl.locked=tru e
endif
next
end sub

Unfortunitly "ctrl.locked=tr ue" is not valid in .net 2.0.
Is there an equivalent method in 2.0 for this?

Thanks


Aug 29 '06 #4
Rich,

NoEdit was a quick way of writting of me, readonly is by instance in the
textbox

http://msdn.microsoft.com/library/de...donlytopic.asp

Enable and disable should work, if you put them in a groupbox you can do
this even in one time. A bad thing from the enable is false is that it shows
up so ugly. However if you create a usercontrol with by instance a method
lock, than you can probably achieve what you want by changing some colours.

http://msdn.microsoft.com/library/de...abledtopic.asp

I assume of course that you are doing this in a windowsform

I hope this helps,

Cor

"RichG" <Ri***@discussi ons.microsoft.c omschreef in bericht
news:97******** *************** ***********@mic rosoft.com...
Hi, thanks for the response
>Not really those who are accessible you can enable and dispable and some
you
can prevent to edit.
I can't find "noedit" and "enabled" doe not work.
>If typeof ctr Is Button then
Yes, that's a better way.. Thanks. I did not think about using "typeof".
I
just have a consistant way of naming controls.

It's strange that this capability which I used so much in a previous
version
of VB is not available here. I only occasionally need to dynamically
"lock"
a control, but it is handy.
In this case I'm trying to make a form for "View" only, so that some
people
can look at the values but cannot change them.
Rich
"Cor Ligthert [MVP]" wrote:
>Rich,

Not really those who are accessible you can enable and dispable and some
you
can prevent to edit.

The normal way to see if something is a button is by the way.

If typeof ctr Is Button then

I hope this gives some help,

Cor

"RichG" <Ri***@discussi ons.microsoft.c omschreef in bericht
news:4C******* *************** ************@mi crosoft.com...
>I want to lock all controls except the buttons on a form. I sometimes
need
the form to call lockForms(Me).

public sub lockControls(fr m as form)
for each ctrl as control in frm
if left(ctrl.name, 3)<>"btn" then
ctrl.locked=tru e
endif
next
end sub

Unfortunitly "ctrl.locked=tr ue" is not valid in .net 2.0.
Is there an equivalent method in 2.0 for this?

Thanks



Aug 29 '06 #5
Cor
Using ReadOnly appears to be available only within the form and not a
reference to the form. And it's only available when the control is
referenced by name and not as part of the controls collection. So I cannot
cycle through the controls collection in a sub that was called and passed the
form as a reference and lock the ones I want locked.
It looks like I will have to create a duplicate form for every form that
needs to be displayed read only, and lock every control on it except the
Close button.
How did we end up with a language has greater funtionallity but is less
funtional in the things we need to do. I guess such is progress....... .....
Thanks Cor
Rich

"Cor Ligthert [MVP]" wrote:
Rich,

NoEdit was a quick way of writting of me, readonly is by instance in the
textbox

http://msdn.microsoft.com/library/de...donlytopic.asp

Enable and disable should work, if you put them in a groupbox you can do
this even in one time. A bad thing from the enable is false is that it shows
up so ugly. However if you create a usercontrol with by instance a method
lock, than you can probably achieve what you want by changing some colours.

http://msdn.microsoft.com/library/de...abledtopic.asp

I assume of course that you are doing this in a windowsform

I hope this helps,

Cor

"RichG" <Ri***@discussi ons.microsoft.c omschreef in bericht
news:97******** *************** ***********@mic rosoft.com...
Hi, thanks for the response
Not really those who are accessible you can enable and dispable and some
you
can prevent to edit.
I can't find "noedit" and "enabled" doe not work.
If typeof ctr Is Button then
Yes, that's a better way.. Thanks. I did not think about using "typeof".
I
just have a consistant way of naming controls.

It's strange that this capability which I used so much in a previous
version
of VB is not available here. I only occasionally need to dynamically
"lock"
a control, but it is handy.
In this case I'm trying to make a form for "View" only, so that some
people
can look at the values but cannot change them.
Rich
"Cor Ligthert [MVP]" wrote:
Rich,

Not really those who are accessible you can enable and dispable and some
you
can prevent to edit.

The normal way to see if something is a button is by the way.

If typeof ctr Is Button then

I hope this gives some help,

Cor

"RichG" <Ri***@discussi ons.microsoft.c omschreef in bericht
news:4C******** *************** ***********@mic rosoft.com...
I want to lock all controls except the buttons on a form. I sometimes
need
the form to call lockForms(Me).

public sub lockControls(fr m as form)
for each ctrl as control in frm
if left(ctrl.name, 3)<>"btn" then
ctrl.locked=tru e
endif
next
end sub

Unfortunitly "ctrl.locked=tr ue" is not valid in .net 2.0.
Is there an equivalent method in 2.0 for this?

Thanks


Aug 29 '06 #6
Rich,

You can reach it,

if Typeof ctr Is Textbox then
DirectCast(ctr, Texbox).ReadOnl y
End if

Just typed here,

Cor

"RichG" <Ri***@discussi ons.microsoft.c omschreef in bericht
news:03******** *************** ***********@mic rosoft.com...
Cor
Using ReadOnly appears to be available only within the form and not a
reference to the form. And it's only available when the control is
referenced by name and not as part of the controls collection. So I
cannot
cycle through the controls collection in a sub that was called and passed
the
form as a reference and lock the ones I want locked.
It looks like I will have to create a duplicate form for every form that
needs to be displayed read only, and lock every control on it except the
Close button.
How did we end up with a language has greater funtionallity but is less
funtional in the things we need to do. I guess such is
progress....... .....
Thanks Cor
Rich

"Cor Ligthert [MVP]" wrote:
>Rich,

NoEdit was a quick way of writting of me, readonly is by instance in the
textbox

http://msdn.microsoft.com/library/de...donlytopic.asp

Enable and disable should work, if you put them in a groupbox you can do
this even in one time. A bad thing from the enable is false is that it
shows
up so ugly. However if you create a usercontrol with by instance a method
lock, than you can probably achieve what you want by changing some
colours.

http://msdn.microsoft.com/library/de...abledtopic.asp

I assume of course that you are doing this in a windowsform

I hope this helps,

Cor

"RichG" <Ri***@discussi ons.microsoft.c omschreef in bericht
news:97******* *************** ************@mi crosoft.com...
Hi, thanks for the response
Not really those who are accessible you can enable and dispable and
some
you
can prevent to edit.
I can't find "noedit" and "enabled" doe not work.

If typeof ctr Is Button then
Yes, that's a better way.. Thanks. I did not think about using
"typeof".
I
just have a consistant way of naming controls.

It's strange that this capability which I used so much in a previous
version
of VB is not available here. I only occasionally need to dynamically
"lock"
a control, but it is handy.
In this case I'm trying to make a form for "View" only, so that some
people
can look at the values but cannot change them.
Rich
"Cor Ligthert [MVP]" wrote:

Rich,

Not really those who are accessible you can enable and dispable and
some
you
can prevent to edit.

The normal way to see if something is a button is by the way.

If typeof ctr Is Button then

I hope this gives some help,

Cor

"RichG" <Ri***@discussi ons.microsoft.c omschreef in bericht
news:4C******* *************** ************@mi crosoft.com...
I want to lock all controls except the buttons on a form. I
sometimes
need
the form to call lockForms(Me).

public sub lockControls(fr m as form)
for each ctrl as control in frm
if left(ctrl.name, 3)<>"btn" then
ctrl.locked=tru e
endif
next
end sub

Unfortunitly "ctrl.locked=tr ue" is not valid in .net 2.0.
Is there an equivalent method in 2.0 for this?

Thanks



Aug 29 '06 #7
Your the MAN Cor!!!!!

When I implemented the code you gave me (after adding .ReadOnly = True), I
found that only three controls were locked. When I ran it through the
debugger, I found that most of the other controls were in hidden by
GroupBoxes. The GroupBox does not have a ReadOnly so I just set
groupbox.enable d=false. That disabled everything in the group box. Then I
found that the DatTimePicker and ComboBox controls would not work in the
syntax you sent me but they would disable.
So I just disabled every thing except the buttons.

Thanks Cor!

"Cor Ligthert [MVP]" wrote:
Rich,

You can reach it,

if Typeof ctr Is Textbox then
DirectCast(ctr, Texbox).ReadOnl y
End if

Just typed here,

Cor

"RichG" <Ri***@discussi ons.microsoft.c omschreef in bericht
news:03******** *************** ***********@mic rosoft.com...
Cor
Using ReadOnly appears to be available only within the form and not a
reference to the form. And it's only available when the control is
referenced by name and not as part of the controls collection. So I
cannot
cycle through the controls collection in a sub that was called and passed
the
form as a reference and lock the ones I want locked.
It looks like I will have to create a duplicate form for every form that
needs to be displayed read only, and lock every control on it except the
Close button.
How did we end up with a language has greater funtionallity but is less
funtional in the things we need to do. I guess such is
progress....... .....
Thanks Cor
Rich

"Cor Ligthert [MVP]" wrote:
Rich,

NoEdit was a quick way of writting of me, readonly is by instance in the
textbox

http://msdn.microsoft.com/library/de...donlytopic.asp

Enable and disable should work, if you put them in a groupbox you can do
this even in one time. A bad thing from the enable is false is that it
shows
up so ugly. However if you create a usercontrol with by instance a method
lock, than you can probably achieve what you want by changing some
colours.

http://msdn.microsoft.com/library/de...abledtopic.asp

I assume of course that you are doing this in a windowsform

I hope this helps,

Cor

"RichG" <Ri***@discussi ons.microsoft.c omschreef in bericht
news:97******** *************** ***********@mic rosoft.com...
Hi, thanks for the response
Not really those who are accessible you can enable and dispable and
some
you
can prevent to edit.
I can't find "noedit" and "enabled" doe not work.

If typeof ctr Is Button then
Yes, that's a better way.. Thanks. I did not think about using
"typeof".
I
just have a consistant way of naming controls.

It's strange that this capability which I used so much in a previous
version
of VB is not available here. I only occasionally need to dynamically
"lock"
a control, but it is handy.
In this case I'm trying to make a form for "View" only, so that some
people
can look at the values but cannot change them.
Rich
"Cor Ligthert [MVP]" wrote:

Rich,

Not really those who are accessible you can enable and dispable and
some
you
can prevent to edit.

The normal way to see if something is a button is by the way.

If typeof ctr Is Button then

I hope this gives some help,

Cor

"RichG" <Ri***@discussi ons.microsoft.c omschreef in bericht
news:4C******** *************** ***********@mic rosoft.com...
I want to lock all controls except the buttons on a form. I
sometimes
need
the form to call lockForms(Me).

public sub lockControls(fr m as form)
for each ctrl as control in frm
if left(ctrl.name, 3)<>"btn" then
ctrl.locked=tru e
endif
next
end sub

Unfortunitly "ctrl.locked=tr ue" is not valid in .net 2.0.
Is there an equivalent method in 2.0 for this?

Thanks



Aug 30 '06 #8

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

Similar topics

6
2801
by: MS | last post by:
Access 97 here. I want a simple way to "lock" certain records on a form. Some records remain "live" until all data is available which happens over time. When all the fields are complete, I want the record to be able to be "locked", or intentionally unlocked. I thought of having a check box called "chkedit" that can be clicked when the data entry for the record is complete. I have the following code in the OnCurrent event for the...
2
1495
by: TechBoy | last post by:
I have 2 forms FrmMain and frmSearch. On frmMain I have to lock the textboxes and combo boxes on the form if the user logged out that record. FrmMain has a command button that launches frmSearch. While frmSearch (which is a regular form, not modal/popup,etc) is up, frmMain sits in the background. The problem is: when frmMain is displaying a locked record, and
0
2297
by: jonelling | last post by:
I am having a problem where the page load event is not being fired for certain user controls that I load dynamically in placeholders. Here is what I'm doing in brief, with full test code supplied at the bottom. In my controlling .aspx page, in the page_init() sub, if not postback, I load two user controls and place them in placeholders. This works and a trace statement in each user control's page load handler is executed on initial...
14
1368
by: Laura T. | last post by:
To synchronize thread access to shared objects, I've always used the lock(shared_object) { } pattern. I've seen many recommendations and examples where to synchronize use lock(another_object) { use shared_object; } pattern. I do not see any reason to have another simple object to lock for since I can lock the shared object directly. Are there any deep implications to use shared lock object to guard the actual shared object, maybe...
7
1450
by: Schroeder | last post by:
I have a DataSet that is cached deep down in a business layer object. Higher up, there's a merge being performed on that object and it very occassionaly throws a NullReferenceException deep down in the merge code. I suspect that the DataSet is being edited during the merge by another thread or its going out of scope (i.e. expiring). The question is whether I can/should lock that reference object. Would it help? For example:
3
1429
by: crgsmrt | last post by:
Hi all, I'd really appreciate it if someone was able to help me out with a problem I'm having with C#. I'm a complete newbie to this, so please excuse what may appear as a stupid question. Basically, I'm trying to write a .NET distributed app (hopefully :p) with Indigo and .NET Framework 2.0 (C# as my language of choice). Anyway, what I have is a client-side object library that, when requested, will create a login form and pass it...
10
2980
by: Ami | last post by:
Hello everyone, I have developed a small access application and now I need to lock my forms against unwanted edits. I have used the code by Allen Browne I found here http://allenbrowne.com/ser-56.html and it works great, but I need to unlock and lock my main form and subform separately, using two different buttons.
1
1379
by: Michael728 | last post by:
Need some help please. There are 4 tables in this database. Six controls on the form are related to the table Degree. The other controls on the form are related to the other three tables. My problem with this form (which was working fine) is that when a new record is created the 6 controls that are from the Degree table are not editable. This occurs randomly with new records, so not all new records will have this problem. The database...
1
1358
by: tim2006 | last post by:
When i try to run the program, it just hangs. If i remove the axwebbrowser control it works fine. Any ideas? Here is my code: class1.vb Imports System.Windows.Forms Imports System.Threading
0
9579
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
10578
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, 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...
1
10321
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
10077
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
9152
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
7620
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
6853
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
5522
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...
2
3820
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.