TDBGrid(s) Compare Values and Paint - delphi

On this form, there are (3) TDBGrids. OnCalcCellColors or OnDrawDataCell, need to compare a value in grid1 with a corresponding value in grid3. The row color for all (3) grids will be determined by the comparison. >= Red, < Green etc...
The coloring is easy. However without ARow & ACol cell references, not sure how to index the grid values. Works great on a single grid.
Doing the comparison in this manner with negate the need to Enumerate the data set.

Related

conditional format only marks one cell if the next values are the same

I am formatting a column in a way that the 2 lowest values are painted green, with the custom formula:
=K6<SMALL($K$6:$K$44; 3)
From my understanding this takes the third lowest value and paints the ones beneath that (the two lowest) green.
This worked fine until, today we had value 168, 169.5 169.5 and values above that. It only colored 168 as green although, 169.5 is the 2nd lowest value. Why does it not mark all 3 green?
Is there a way I can easily fix this ? So that it always marks the 2 lowest values, even if there are multiple of them.
You asked for conditional formatting that:
...always marks the 2 lowest values, even if there are multiple of them.
Try the following formula
=OR(K6=MIN(SORTN($K$6:$K$44,2,2,1,1)),K6=MAX(SORTN($K$6:$K$44,2,2,1,1)))
(Do adjust the formula according to your ranges and locale)
Try rank(), like this:
=rank(K6; unique(K$6:K$44); true) <= 2

conditional formatting for a full column based on the average value in that row?

I'm going through a sheet with multiple different data points across different rows (for different versions of the same action each on their own row).
In order to easily compare from one row to the next, I would like to use conditional formatting to on a simple level as follows: - highlight cell green if a value in that cell is equal to or greater than average for that column - highlight cell red if a value is less than average for that column
So for example, I need all cells in column F to be green if the value in each cell is equal to or greater than the average of all values in that column or red if it's less than the average of all values in that column.
But I'm struggling to get that working.
Does anyone have any ideas?
I tried in 2 ways, trying to get a custom formula that calculates this average and merely doing greater than or less than in reference to a specific cell in another column (I have a separate column where I only have the average of each column calculated as follows: =Average(E3:E18) but neither is working consistently, it's highlighting some cells green that should be red and vice versa.
green color:
=IF(AVERAGE(F:F)<=F2, 1)
red color:
=IF(AND(AVERAGE(F:F)>F2, F2<>""), 1)
Maybe what you want is this CF formula rule:
=D2<average(D:D)
applied to the whole of D2:Rx (where x is last row) for red, and a corresponding rule with < replaced by >= for green (or simply format all range with 'standard' fill of green).

Condition Formatting, changing the ranges colour depending on the total of that range

I want to conditional format some cells so that if the added value of those cells = 0 it goes green and then a separate one if the sum does not equal 0. Currently, I am using a total cell to determine this (BALANCE LEVEL), but I want to eliminate the use of this and have the format rule to sum the values and determine the colour without the use of this cell.
Custom formula is
=SUM(AQ39:AQ48)=0
This to turn the column green
and then another rule with this formula
=SUM(AQ39:AQ48)<>0
This to turn the column red
I expected this to change the column green if the total of all the values in that column = 0, and red if the sum does not. It only changes some of the cells, even though the range I have applied it to is that whole column.
Please clear any existing CF from your range, fill it 'standard' red fill and apply this CF formula rule with green fill:
=SUM(AQ$39:AQ$48)=0
Beware of floating point errors.

How to duplicate (not extend) conditional formatting rule?

I have a conditional formatting rule (color scale) applied to a row (e.g. A1:Z1). I want the to duplicate this rule for another row, but when I use Paste Special -> Paste Conditional Formatting Only (or Paint Format tool), it simply makes the color scale rule to apply to the sum of ranges (e.g. A1:Z2). The problem is that it won't process ranges separately, it will just join them into a single range and find the biggest / smallest number over the joint range, rather than in individual ranges.
The same applies if the range is defined in format "A1:Z1,A2:Z2".
What I want is just to avoid defining the same color scale rule for different rows manually.
Note that Google Sheets behaves here differently from MS Excel. In Excel I get the desired behaviour very easily and intuitively: I create a rule for a row, select it, copy, then paste special formatting only. For a scale from smallest red to biggest green, this is the output:
!Excel colour scale example]1
If I do the same steps in Google Sheets, the output is quite different:
It is clear that GS does not duplicate a rule, but simply adds a new range to the computed joint range the original rule applies to.
Is there a way in GS to do the same conditional rule duplication that Excel does, or I just have to re-create it manually?
Click any cell covered by the original conditional formatting
In the menu, pick format/conditional formatting...; this opens a side panel with all conditional formats that apply to that cell
Click the format you want to duplicate
Do not edit anything yet
Click "Add another rule" on the bottom. This will save any changes you made to your original format ... and open a new clone.
Change the range on the newly created clone.
Repeat 5 and 6 until you enter the last range
Click "Done".
I am not saying I LIKE this answer, but it is the only solution I can come up with:
Apply Custom Formatting using a Custom formula for each color value. In your example, this means 6 entries in the Custom Formatting. For each one, use the below formula. For the Highest value, use:
=A1=LARGE($A1:$G, 1)
For the second highest value, use:
=A1=LARGE($A1:$G, 2)
Increment the last number for each ranking, setting a color for each as well. I hope your range to Z does not mean you are color coordinating that many items. My concern there would be not just having that many conditional format items, but having that many colors be meaningful.
There is also the MAX() and MIN() functions if you just want the highest and lowest.
=A1=MAX($A1:$G)
or
=A1=MIN($A1:$G)
as well as MEDIAN() and SMALL() which is the opposite of LARGE(). In case you want the X largest and Smallest, or Maximum, Minimum, and Median.

How does a DBGrid component determine initial column widths to display?

I'm having a difficult time saving/reloading col widths in a DBGrid (actually TMS's DBGrid). TMS includes built-in methods to save/reload col widths, which are working correctly (I can read the values in an ini file). Something, somewhere in my code is overriding the stored values, however. I don't know enough about how col widths are determined to be able to debug the issue.
The grid is ultimately connected to a ClientDataSet file.
TColumn has a method named DefaultWidth, which is called in particular when the width hasn't been explicitly assigned to the column (which is true for the dynamically created grid columns).
Basically, it takes the column's associated field's display width (in chars) and multiplies it by the width of the 0 character (in pixels), using the corresponding font.
It then compares the result to the width of the title (in pixels) and returns the greater value.

Resources