[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Change read-only attribute of edit control programmatically.

Posted on 2002-06-02
4
Medium Priority
?
546 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
ID: 7050457
How about overriding the OnChar in your derived edit control class and disabling all charaacters ?
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 7050535
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 31

Accepted Solution

by:
Zoppo earned 400 total points
ID: 7050723
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
ID: 7066136
I knew it would be a simple answer - I just couldn't get my thinking gear around it :(

Thanks
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Screencast - Getting to Know the Pipeline
Suggested Courses

872 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