Solved

Change read-only attribute of edit control programmatically.

Posted on 2002-06-02
4
471 Views
Last Modified: 2013-11-20
I have an application using DAO recordsets. My client requires one field to be set to read only if a particular parameter is passed to the application. If no parameters are passed the field is to be enabled.

I used the EnableWindow method to enable/disable the field as required but my client insists that it be read only since he does not want the text to be grayed out.

I have searched through the help files and I'm sure the answer to this one is ridiculously simple - I just can't see it :(

I am using VC++ Version 6, latest SDK, on a 1.6GHz , 1GB P4 running XP Pro.
0
Comment
Question by:AveryH
4 Comments
 
LVL 1

Expert Comment

by:gurly
Comment Utility
How about overriding the OnChar in your derived edit control class and disabling all charaacters ?
0
 
LVL 23

Expert Comment

by:Roshan Davis
Comment Utility
Don't use EnableWindow().

Making read only, user can select the text, but disabling will disable the edit.

You can use the ModifyStyle function with ES_READONLY attribute.

If you need the back color as white, you just override the OnCtlColor.

Why becoz, ES_READONLY is also shows the edit content in gray color.


GOOD LUCK
0
 
LVL 30

Accepted Solution

by:
Zoppo earned 100 total points
Comment Utility
Hi AveryH,

you can use CEdit::SetReadOnly() or EM_SETREADONLY message
to set/clear ES_READONLY style.

to roshmon: modifying readonly-state of a edit control
via ModifyStyle() with ES_READONLY does not work (as
stated in MSDN article about CWnd::ModifyStyle).

hope that helps,

ZOPPO
0
 

Author Comment

by:AveryH
Comment Utility
I knew it would be a simple answer - I just couldn't get my thinking gear around it :(

Thanks
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Folder Comparison 12 52
difference between String.subString() and String.subSequence() 6 133
bigDiff challenge 17 74
fix34  challenge 9 95
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa‚Ķ
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now