Prevent user from changing text box on Windows Form

Mike_Stevens
Mike_Stevens used Ask the Experts™
on
I have a windows form project that depending on the user i need to make certain text boxes read only.  I have tried using the following but it does not seem to have an effect and does not make it read only.

Me.Textbox1.Readonly = True

I am not sure if this is the correct approach.

Any help would be appreciated
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
corvetteguruDBA/Systems Analyist

Commented:
Which version? In certain versions you can me.txtbox.locked = true, but you can't do that in 2010... or 2008, IIRC.

You can always use me.txtbox.enabled = false, the downside is you can't see it as well.

But Readonly is the acceptable property, when I double checked it, the help text says "Controls whether the text in the edit control can be changed or not." Sounds pretty definitive.

Finally, you just don't update those fields when you hit save.

Author

Commented:
Visual Studio 2010
DBA/Systems Analyist
Commented:
Then my answer is the one you need... I am also using 2010!
JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

Mike TomlinsonHigh School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
Top Expert 2009

Commented:
Are you sure it's not working?

Readonly() prevents changes to the TextBox, but the user can still interact with the control.  The cursor changes and the user can select text and even copy it...

Author

Commented:
I can selected text and change it even after i set the readonly property to true
Mike TomlinsonHigh School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
Top Expert 2009

Commented:
Can you post more code then?...or possibly upload a sample project?

Commented:
readonly, is the correct approach.
you can also install infragistics and use ultratextbox which has differnt ways of disabling it.


If you really want to be classy, put a transparent label over the textbox. and use senttoback / sendtofront
instead of readonly
corvetteguruDBA/Systems Analyist

Commented:
I have used infragistics... unless it  has improved, it is an overweight pig with some serious issues. I used it with .NET 2005... pretty, yes, reasonably functional, but the actual implementation leaves a lot to be desired. Oh, and it's REALLY expensive.

Commented:
Its been heavily improved,  now its a colossal pig,  but they update it at least twice a year,  so the bugs are gone
corvetteguruDBA/Systems Analyist

Commented:
Thank God the bugs are out... it made the product seriously unwieldy. Have they improved the performance of the various grids?
corvetteguruDBA/Systems Analyist

Commented:
Any status update on this issue?

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial