Solved

Change read-only attribute of edit control programmatically.

Posted on 2002-06-02
4
506 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 100 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Looking for a specific application/software 2 110
pre4 challenge 19 100
Dell Alienware Graphics Amplifier Driver for non-Alienware systems 18 256
JQuery serialize and unserialize 8 87
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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…
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.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

803 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