Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Change read-only attribute of edit control programmatically.

Posted on 2002-06-02
4
Medium Priority
?
544 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

650 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