Avatar of Mike_Stevens
Flag 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
Visual Basic.NETMicrosoft Development.NET Programming

Avatar of undefined
Last Comment
Andy Bogus

8/22/2022 - Mon
Andy Bogus

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.

Visual Studio 2010
Andy Bogus

View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
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...
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck

I can selected text and change it even after i set the readonly property to true
Mike Tomlinson

Can you post more code then?...or possibly upload a sample project?
Ess Kay

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
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Andy Bogus

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.
Ess Kay

Its been heavily improved,  now its a colossal pig,  but they update it at least twice a year,  so the bugs are gone
Andy Bogus

Thank God the bugs are out... it made the product seriously unwieldy. Have they improved the performance of the various grids?
Your help has saved me hundreds of hours of internet surfing.
Andy Bogus

Any status update on this issue?