Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
16
Erster Beitrag:
vor 3 Jahren, 7 Monaten
Letzter Beitrag:
vor 3 Jahren, 7 Monaten
Beteiligte Autoren:
Malc, Adrian A., Jose Antonio Garrido, Fabrice Harari, Al

How to get a readonly cell in a table

Startbeitrag von Malc am 10.04.2014 11:13

Hi Folks,

I am trying to programatically set individual cells in a table to be editable or readonly

As far as I can tell, the only state attributes available for a cell are

Active 0
Grayed 4
ReadOnlyNoSelection 5



Grayed and ReadOnlyNoSelection are useless as they do no allow clicking on the cell or selecting text

I have tried other options to no avail

DisplayOnly/Inactive 1
2 ???
3 ???

Anyone got any ideas on how I could implement this seemingly very simple basic concept????

Perhaps I should add a message to the Polemic criticism about windev thread :)

Cheers

Malc

Antworten:

Hi.
Well, as you said the attribute "ReadOnlyAndAllowSelect" is not available on table cells.

Maybe you can use one of this workaroud that I just thought:

1. you can restore the orignal value in the process "Whenever Modified". (or in the processs "Exit in COL_Name" )

2. You can also use a looper control instead of a table, since it has much possibilites that aren't available on tables.

If its only for the "ReadOnlyAndAllowSelect" property, then doesn't worth the extra work of the looper.

Note: I know "ReadOnlyAndAllowSelect" is not the correct name... it's just to explain it.

Regards,
José Antonio.

von Jose Antonio Garrido - am 10.04.2014 12:13
Hi Malc,

One way is try making all cells editable (table=editable) and then restrict specific cells to non editable, for example:

End of initialization of TABLE_Name
TABLE_Name[x][y]..state=ReadOnlyNoSelection //where x is the row and y is the column.

The user can copy the value of any cell by right click on it.

Adrian

von Adrian A. - am 10.04.2014 13:43
Hi Adrian
Quote
Adrian A
Hi Malc,

One way is try making all cells editable (table=editable) and then restrict specific cells to non editable, for example:

Displaying a row of TABLE_Name
TABLE_Name[x][y]..state=ReadOnlyNoSelection //where x is the row and y is the column.

The user can copy the value of any cell by right click on it.

Adrian

Unfortunately, the mouse/row select/double click doesn't work well in this instance, and also the right click only seems to work if moving from current column, and you can't do anything at all via keyboard.

von Malc - am 10.04.2014 14:06
Hi Jose
Quote
Jose Antonio Garrido
Hi.
Well, as you said the attribute "ReadOnlyAndAllowSelect" is not available on table cells.

Maybe you can use one of this workaroud that I just thought:

1. you can restore the orignal value in the process "Whenever Modified". (or in the processs "Exit in COL_Name" )

2. You can also use a looper control instead of a table, since it has much possibilites that aren't available on tables.

If its only for the "ReadOnlyAndAllowSelect" property, then doesn't worth the extra work of the looper.

Note: I know "ReadOnlyAndAllowSelect" is not the correct name... it's just to explain it.

Regards,
José Antonio.


Yes, I can get this to work.
I have created a common CellGotFocus local procedure called from every column enter/row enter event and store the current value, e.g. gsLastValue = Myself

Then I created a common CellModified local procedure called from every column modified event, which then checks for a custom readonly property, which if set, restores the value.
Excellent. :cheers:

I also devised an even more cunning but less simple method: :p
In the CellGotFocus event, if the flag is readonly, I initialise a readonly event
e.g. Event(MyReadonlyEvent, , WM_CHAR)
This MyReadonlyEvent returns a value, doesn't matter what, but immediately throws the character away.
I create a common CellLostFocus called from all the lost focus events which EndEvent(EventID) the MyReadOnlyEvent.
It works!

However, I think I'll stick with your variant. I'm not too sure what the long term impact of enable/disabling a custom event would have...


Cheers

Malc

von Malc - am 10.04.2014 14:24

Re: How to get a readonly cell in a table REVISITED

Hi
OK, after playing further, I have actually decided to implement my dynamic event routine instead.

The reason is that it does not fire the "when modified" event and therefore if you accidentally type into a readonly field, it won't put you in edit mode (most of the forms in our applications switch to edit mode as soon as you start editing, displaying save/cancel buttons etc)

Cheers

Malc

von Malc - am 10.04.2014 15:47
Hello Malc

I presume that if the cell is set to read only that the user requirement is to extract the cell info ?
Could you use the mouse hover event to copy the cell contents int the clipboard ? A tooltip in the cell triggered from either the help or the hover event could informt the user of what has happened.

Regards
Al

von Al - am 10.04.2014 16:12

Re: How to get a readonly cell in a table REVISITED

Malc, I tried what you said, and the result is amazing. Just as if it where natively done.

But i have one question, how did you find out that the "windows event" to intercept (and later cancel) was "WM_CHAR" (258) ?

Regards,
José Antonio.

von Jose Antonio Garrido - am 10.04.2014 16:30

Re: How to get a readonly cell in a table REVISITED

Hi José
Quote
Jose Antonio Garrido
Malc, I tried what you said, and the result is amazing. Just as if it where natively done.

But i have one question, how did you find out that the "windows event" to intercept (and later cancel) was "WM_CHAR" (258) ?

Regards,
José Antonio.


In the test form I created, I put traces in all the key events (up/down/press)
The title of the key pressed event is:
Key Pressed (WM_CHAR) of Table1
I then added code to return various values from all the events, and also tinkered with
_EVE.return etc. Process of elimination.

I have had a few decades worth experience with keypress events and APIs in VFP and VB
It has to be said they both handle this sort of thing better. (and also make it easier to set table/grid cells readonly...). Alas, they are no more.

Cheers
Malc

von Malc - am 11.04.2014 09:52
Hi Al
Quote
Al
Hello Malc

I presume that if the cell is set to read only that the user requirement is to extract the cell info ?
Could you use the mouse hover event to copy the cell contents int the clipboard ? A tooltip in the cell triggered from either the help or the hover event could informt the user of what has happened.

Regards
Al


I just want a default readonly setting, so that all the usual double click and text selection works, but no editing/modified status changes.
In this particular instance, I have a mutlitude of cells in a row which can be editable or not based on the status of other fields.
I have to say that the missing Inactive/Readonly state is definately an oversight and I will report it to PC Soft. In the mean time, I have a work around using a customs event.

von Malc - am 11.04.2014 09:57

Re: How to get a readonly cell in a table REVISITED

OK, one last issue I just discovered.
If the cell is not 'officially' readonly, the right click menu option has the cust and delte options enabled.
I will have to see if I can disable these in some way....

von Malc - am 11.04.2014 10:08

Re: How to get a readonly cell in a table OUCH!BRICK WALL

OK, some issues with my solution.
Right click menu does not appear to be dynamically configurable, so cannot disable cut or delete options (I've checked out the ConfigureAAF/DisableAAF and even attempted to enum Table1..PopupMenu - no go)

Also, the delete key (and probably backspace) also still wipe the cell and set the modified status.

Looks like I might need to go back to resetting the initial value in the When Modified event.



Malc

von Malc - am 11.04.2014 11:43
Hi Malc,

You can eliminate the implementation of custom readonly property by using the cell properties itself. Lets say for readonly cells, you can set the color blue after table initialization, then later, just check for the blue color in corresponding event.

Adrian

von Adrian A. - am 11.04.2014 11:55

Re: How to get a readonly cell in a table OUCH!BRICK WALL

Hi Malc

Quote
Malc
Right click menu does not appear to be dynamically configurable, so cannot disable cut or delete options (I've checked out the ConfigureAAF/DisableAAF and even attempted to enum Table1..PopupMenu - no go)


Actually, from the top of my head, you can declare your OWN right clic menu and affect it to the table instead of the system one... In that case, you have full control of what's going on when

Quote
Malc
Also, the delete key (and probably backspace) also still wipe the cell and set the modified status.

Looks like I might need to go back to resetting the initial value in the When Modified event.


Maybe not... System keys just have to be intercepted via a different event (WM_SYSCHAR, from the top of my head)

Best regards

von Fabrice Harari - am 11.04.2014 13:22

Re: How to get a readonly cell in a table OUCH!BRICK WALL

Hi Fabrice
Quote
Fabrice Harari
Actually, from the top of my head, you can declare your OWN right clic menu and affect it to the table instead of the system one... In that case, you have full control of what's going on when

Yep, got that. Would mean replicating all default functionality, which was more work than I really wanted to do :)

Quote
Fabrice Harari
Maybe not... System keys just have to be intercepted via a different event (WM_SYSCHAR, from the top of my head)

Ah, now that is interesting.

I shall investigate further...

Cheers

Malc

von Malc - am 11.04.2014 13:39
Hi Adrian

Quote
Adrian A.

You can eliminate the implementation of custom readonly property by using the cell properties itself. Lets say for readonly cells, you can set the color blue after table initialization, then later, just check for the blue color in corresponding event.

Adrian


Yes, I'm already doing something like that after I found the ..Note property wasn't cell specific. I'm actually just adding a slight offset of 3 to the default color setting which I can check for but is not noticable

Cheers

Malc

von Malc - am 11.04.2014 13:42
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.