Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
9
Erster Beitrag:
vor 4 Jahren, 6 Monaten
Letzter Beitrag:
vor 4 Jahren, 6 Monaten
Beteiligte Autoren:
JP, Al, Fabrice Harari, Eric Wiegert

[WD18] - Background Colour of a single table cell

Startbeitrag von JP am 12.02.2014 15:27

Hi All,

Is there a way to change the colour of a particular table cell depending on the contents of that cell? For example, if the value is negative then the background of just that one cell should be red and otherwise white. Obviously this would need to evaluate each row/cell dynamically at runtime. Such a thing possible?

Thanks

Antworten:

Hi JP

of course...

ColumName[RowNumber]..

will give you access to all the possible properties, including color

Best regards

von Fabrice Harari - am 12.02.2014 16:09
You can produce the desired result with code in the "Displaying a row of " for your Table
Something like:
IF table[CurrentSubscript].col1 = 2 THEN
table[CurrentSubscript].col1 ..BrushColor = iLightRed
END

Now you should consider the following:
The "Displaying a row of " for your Table is fired differently depending upon the type of table you have "Memory" or "Browsed".
"Memory" Tables - code is fired once when filled
"Browsed" Tables - code "may" be fired multiple times or once - depends upon if your "Direct Access" or specify N Max records in memory.

You will also have to consider the following:
1) When you "Select" the row a totally different style is applied to your changed Background & Color hiding your result.
2) Editing the Table cells after filling will require more code (in the Selecting a row & Modifying a cell) to recheck the state of the value etc.
3) If you move the code to a general procedure as to call it from "Display / Select / Edit you will have to determine the "CurrentSubscript" and pass it as a parameter cause that property is only available in the "Displaying a row of " for your Table

I have found that the easiest way to communicate to the user a different value in a cell is to do the following - also in the code in the "Displaying a row of " for your Table
IF table[CurrentSubscript].col1 = 2 THEN
table[CurrentSubscript].col1 = Alignment("C",gPen(LightRed)+table[CurrentSubscript].col1 )
ELSE
table[CurrentSubscript].col1 = table[CurrentSubscript].col1
END
This is unaffected by the style changes / Z-Order of elements

As always check the relevant help sections to alter to your liking

Hopefully my answer makes sense

Eric W

von Eric Wiegert - am 12.02.2014 16:36
Thanks Fabrice. I shall experiment and see what I can come up with.

von JP - am 12.02.2014 17:32
Thanks Eric! Great reply - I shall investigate tomorrow and let you know how it worked out. Thanks again!

von JP - am 12.02.2014 17:33
Hello JP

The syntax I use in the table display code is the older style where "Table" is the name of the table.

Table[Table][3]..brushcolor = IlightRed //to set the background colour
Table[Table][3]..color = IWhite //to set the text colour

Table[Table] returns the current row number
The number in the last bracket [3] is the column number

Regards
Al

von Al - am 12.02.2014 19:06
For prosperity here is a good link to table colouring from WinDev help:

http://doc.windev.com/en-US/?1013231

von JP - am 13.02.2014 09:42
Is there anyway to set the Odd / Even - Background/Foreground row colours in code? These settings are available in design time.

I know that I could dynamically set the colours using modulo() function on the row number but if the table gets sorted by the user then one would need to reset the colours again which I am sure will be slower than WinDev's internal method. Is there a function/method to tell WinDev what colour to use for odd/even/background/foreground at runtime?

I guess the question is; can one set these settings before the table is even populated so that WinDev handles the colours internally?

von JP - am 13.02.2014 09:49
Some feedback -

I programmed my own column sorting routine using the ability to trap column header click events (http://doc.windev.com/en-US/?1013288&name=programming_the_table_columns&q=column%20header). This is very useful since one can apply custom sort orders combing multple columns with TableSort(). Then implemented an odd/even row colouring routine using the isOdd() function which runs after the sort routine. This seems to work very fast so seems like a good solution. Thanks for the input.

von JP - am 13.02.2014 13:08
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.