Solved

Change read-only attribute of edit control programmatically.

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Suggested Solutions

Title # Comments Views Activity
iSeries FTP Exit Program 8 163
conditional code and condition difference 9 85
NotAlone Challenge 20 88
sumHeights2  challenge 7 132
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…
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

696 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