Link to home
Start Free TrialLog in
Avatar of Mike_Stevens
Mike_StevensFlag for United States of America

asked on

Prevent user from changing text box on Windows Form

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
Avatar of Andy Bogus
Andy Bogus
Flag of United States of America image

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.
Avatar of Mike_Stevens


Visual Studio 2010
Avatar of Andy Bogus
Andy Bogus
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mike Tomlinson
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...
I can selected text and change it even after i set the readonly property to true
Can you post more code then?...or possibly upload a sample project?
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
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.
Its been heavily improved,  now its a colossal pig,  but they update it at least twice a year,  so the bugs are gone
Thank God the bugs are out... it made the product seriously unwieldy. Have they improved the performance of the various grids?
Any status update on this issue?