Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Textbox not editable

Status
Not open for further replies.

D2C

Programmer
Aug 27, 2001
86
BE
Hi there,

Probably this will be an easy question for others, but it has been bothering me since I made my new form based on my class and my tables...

The textboxes I use to get the data from my table should be read only, the user shouldn't be able to click or edit the box until he presses EDIT. I don't want to disable the fields because it grays out and the visibility is 50% less...

Can somebody please tell me how to do this?

tnx a lot!
greetz

d2c
 
The textboxes I use to get the data from my table should be read only, the user shouldn't be able to click or edit the box until he presses EDIT. I don't want to disable the fields because it grays out and the visibility is 50% less...

I assume that your form has an editMode property and that your controls also have an editMode property and that when the editMode of the control matches the editMode of the form, the control is editable. Assuming this to be the case, this code in the control's When() method should do the job:

Code:
IF UPPER( ALLTRIM( Thisform.cEditMode ) ) $ UPPER( ALLTRIM( This.cEditMode ) ) OR UPPER( ALLTRIM( This.cEditMode ) ) == [ALL]
  RETURN .T.
ELSE
  RETURN .F.
ENDIF


Marcia G. Akins
 
Covering some basics first...

- According to Windows UI guidelines, there is supposed to be a visual difference between disabled and read only. It gives the user a clue that there is a difference between the two.
- While it may look greyed out on your PC, it may look different on the user's PC due to their color choices in Windows display settings.
- Most developers seem to want to use an Edit button because it makes the code easier to write. However, look at the way most common applications work. In Word, you don't need to click anything to start writing. In Excel, you get a worksheet when launching. In both applications, to edit a particular file, you only need to open the file and it is in Edit mode...no additional button to click. Why not make your application work the same way?

Craig Berntson
MCSD, Visual FoxPro MVP, Author, CrysDev: A Developer's Guide to Integrating Crystal Reports"
 
Hi Mike.

use the ReadOnly property
[\quote]

I was under the impression from D2C's original post that he did not want the control to get focus if the form was not in edit mode. If it is ReadOnly, it can still get focus.

Of course, it may be that I misunderstood what the goal was ;-)



Marcia G. Akins
 

Marcia,

I was under the impression from D2C's original post that he did not want the control to get focus if the form was not in edit mode.

Of course, your're right. But he also said he didn't want to disable it. Oh, wait .. he doesn't want to disable it because he doesn't like the 50% visibility. So, I suppose the real short answer is to change the DisabledBackColor and DisabledForeColor.

Personally, I'd go with the ReadOnly option. I think it's good that the user can give focus to a control even when the form is not in edit mode. For example, they might want to copy the contents to the clipboard.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-crystal.com)
 
Hi Mike.

Personally, I'd go with the ReadOnly option

In general I agree with you. However, there are some controls that do not have a ReadOnly property, such as a listbox. Also, setting the ReadOnly property of a combo box of style=2 has no effect on it because ReadOnly applies only to the portion of a control that accepts text.

Finally, I know that in some of my forms, I use a grid to navigate through the records in small tables. In this case, it would be very bad to allow the user to navigate off the current record when he is in the middle of editing it ;-)

I am sure that you are aware of these issues. I was just raising them for the benefit of other people.




Marcia G. Akins
 
Dear craig,

Most developers seem to want to use an Edit button because it makes the code easier to write. However, look at the way most common applications work. In Word, you don't need to click anything to start writing. In Excel, you get a worksheet when launching. In both applications, to edit a particular file, you only need to open the file and it is in Edit mode...no additional button to click. Why not make your application work the same way?

Word and excel files are not files that are shared in a multi-user environment, if you choose to let everybody change the fields whenever they want, you will ask for problems in your db.
If the user clicks on EDIT, the record from that specific table will be buffered, and when he applies the changes, it will take the record in private for a second to update.
If I let the textboxes editable, there will be no clear formatting of the screen. The user has to be informed that he needs to click edit before he changes something.

Thank you all for your replies, but apart from the code that Marcia wrote, I am not getting any further. I am a newbie to VFP (using 9), and I'm wondering that it is a setting in my form or my control??

Can't I put a method on my form that does the trick?

tnx a lot for all your help on this one.

greetz
d2c
 
I've not had problems in my DB and I don't have an Edit button. The trick is to put code into the InteractiveChange event of the controls that sets a flag to indicate the state of the data (New, Edit, Read) and if needed, lock the record in the table. As I've taken this approach and retrained users, they have commented they like this method better that the old Edit button style. But, your mileage may vary.

Another option to do it the way you want is to have a custom property (llEditMode) on the form is set to .T. when editing and .F. when not and then in the When of each control have something like this:

RETURN ThisForm.llEditMode

If llEditMode = .F., the WHEN will return .F. and won't allow access to the control. The problem with this is that there is no visual clue on the control that it can't be edited as its color won't change. That can frustrate users.

Craig Berntson
MCSD, Visual FoxPro MVP, Author, CrysDev: A Developer's Guide to Integrating Crystal Reports"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top