Windows Develop Bookmark and Share   
 index > Windows Forms General > Disable data-bound textboxes without making them look disabled.
 

Disable data-bound textboxes without making them look disabled.


I have a form with a very large amount of data-bound textboxes on it. Only a small amount of those textboxes should be edited by the user. The rest are for information only. I need all of the information-only textboxes to be locked.

I can't use Enabled=False because it gray out the background and text so you can barely see what's in the textbox. I can't use Read-Only=True because is also grays out the box and still leaves it as an active textbox, so the user would have to tab through a hundred read-only textboxes just to get to the ones that they can edit.

I've seen a few ways out there to make a custom textbox for something like this, but I'm dealing with the standard data-bound textboxes that get created by VS.NET when I drag items from the datasource.

Any ideas?

WATYF
WATYF  Friday, September 12, 2008 5:42 PM

OK, I've got something that seems to work OK. It just takes a bit of changes.

If you highlight all of the controls, you can set their ReadOnly property to False, set the TabStop to False, and set the Cursor to "Arrow".

It still allows the user to highlight the text within the textbox, but I guess this is close enough. The sad part is that this is really easy to do (the right way) in the old VB (even VBA).


WATYF
WATYF  Friday, September 12, 2008 6:50 PM

WATYF,

What you are looking for areLabel controls. Label controls by default are already set up to do what you want to do. The user cannot select the text, and obviously it is read only. I have Labels in my program that display constantly changing data set up with a BorderStyle = None, and a FlatStyle = Standard. Also, with a Label control, you can set the BackColor property to transparent (unlike a TextBox control.)

As an easy way to make changes to the Label control properties, or the TextBox properties,you can ctrl+select all of the textboxes that you want, and then change those properties for all of those textboxes at the same time.

I hope this helps.

Bob

BobLeavell  Saturday, September 13, 2008 1:38 AM

OK, I've got something that seems to work OK. It just takes a bit of changes.

If you highlight all of the controls, you can set their ReadOnly property to False, set the TabStop to False, and set the Cursor to "Arrow".

It still allows the user to highlight the text within the textbox, but I guess this is close enough. The sad part is that this is really easy to do (the right way) in the old VB (even VBA).


WATYF
WATYF  Friday, September 12, 2008 6:50 PM

WATYF,

What you are looking for areLabel controls. Label controls by default are already set up to do what you want to do. The user cannot select the text, and obviously it is read only. I have Labels in my program that display constantly changing data set up with a BorderStyle = None, and a FlatStyle = Standard. Also, with a Label control, you can set the BackColor property to transparent (unlike a TextBox control.)

As an easy way to make changes to the Label control properties, or the TextBox properties,you can ctrl+select all of the textboxes that you want, and then change those properties for all of those textboxes at the same time.

I hope this helps.

Bob

BobLeavell  Saturday, September 13, 2008 1:38 AM

You can use google to search for other answers

Custom Search

More Threads

• Simple open source utility for generating simple reports
• Change ToolStrip BackgroundImage resource programmatically
• making controls resizable for user
• please help a newbe!!!
• CodeAccessPermission.Demand() vs. Assert()
• Refactoring a Win Forms Application
• Show at Mouseposition
• email attachment readonly
• DateTimePicker in a MenuStrip
• run .exe with command line arguments in Visual c# windows form application