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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ReadOnly and CheckBox question

Status
Not open for further replies.

Nro

Programmer
May 15, 2001
337
CA
Hi all

I have one checkbox with other controls in a form and this checkbox in bound to a field in an updatable view. By default, all the controls in this form are disabled (textbox, combo and checkbox), so the user can’t modify any data. If he wants to modify something, he has to click on a button and all the controls became enabled, to save his modifications, click on OK button and the view is updated and all the controls are disabled again. It’s a very common design.

Now, the appearance of a disable checkbox is very ugly, so instead of disable it, I tried to “ReadOnly” it. If the user click on the checkbox, nothing appear (like it’s suppose to), but in the buffer of the view, the Getfldstate() is changed (dirty record). I don’t want to do a TableRevert(), each time.
If I’m using ReadOnly for a textbox, it’s working ok (no change in the view buffer).

Why is it different for the checkbox?

Thanks in advance.

Nro
 
Hello Keith

The purpose of the form is to allow the user to view and modify data. The reason why I deactivate all the controls is to prevent unwanted modification of the data. If he click on a checkbox, in view only mode, I expect no modification of the view for the field bound to that checkbox.
My question is, again, why I can’t simply change the Readonly property to true for a checkbox. It’s not supposed to change the view buffer if the user click on it, but it does.
Thanks
Nro
 
I am sure you are aware that if a record is deleted and restored, even when the value has not changed, getfldstate() will say it has changed... So not very reliable.
We do this all the time, like you disable and enable controls and extensive use of Readonly, including checkboxes and have never felt a need to do a tablerevert(), one way to be absolutely sure is requery the view, without saving, and see if you get the error, "Values have changed..." (something similar, cannot remember what the exact error message is)... I am sure you will not get the error.
The above is only good if you are not using getfldstate() to determine an action.
 
Nro,

I've had exactly the same problem. The solution is not to make the checkbox readonly, but to change its appearance when it's disabled.

First, I set the DisabledForeColor to dark blue (which is the colour I use for the labels in my data-entry forms). Then, I programmatically set the ForeColor to dark blue when it's disabled, and to black when enabled. It still has a slightly washed-out look, but it looks a lot better than the default settings.

Try playing with this a bit, and you might find some colours that your're happy with.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Thanks for yours suggestions

Imaginecorp, all your assumptions are right. I’m only checking if the view buffer is dirty (getfldstate(-1,viewname)) to see if the user change something or not. If all the controls on the forms are disables / readonly, the data never change, so I never have to verify if the buffer get dirty. All this is true, except for checkbox. If you click it and its readonly, the data does not change, but the buffer get dirty… bizarre?

Mike, I’ll try to change the forecolor of disable / enable checkbox, but again, I think it’s odd that the readonly property does not have the same behaviour as other controls.

Thanks again.

Nro
 
Why not use Getnextmodified(0), but with a twist. If you are checking only a single row, Do a
Go Top
....getnextmodified(0)....
if checking all records do a :
Go Top
....Getnextmodified(0) # 0
Now you will also get new records inserted as they will have negative numbers
 
Nro,

I think it's odd that the readonly property does not have the same behaviour as other controls.

I wish it did. Another issue is that, in a read-only checkbox, the little square (where you place the tick) is always white, which makes it look read-write.

In my own data forms, I don't disable the controls when going out of edit mode -- I generally make them read-only. This works better for most controls. Any text in the control is easier to read, plus the controls can still receive focus (so the user can select text and copy it to the clipboard, for example).

I have generic code that iterates the controls, setting the ReadOnly property in each case. I don't want to take special action in the case of checkboxes, so I have a ReadOnly_Assign method in my base checkbox class that traps any attemtps to change the ReadOnly property, and sets the Enabled instead.

Combo boxes have a similar problem. If you make a combo box read-only, the user can still drop the list down, but any selections are ignored. That's not very intuitive, so I use the same technique of trapping the ReadOnly setting and diverting it to Enabled.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top