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

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.

Related

Fastreport and Delphi Berlin: How to put multiple records fields in one line

I would like to make a master-detail report with fast reports in Delphi Berlin where the detail field date should be printed next to each other in one line. Can someone tell me which property must be set for printing next to each other?
Thanks
ANd here is the result:
You can get a multi-column detail band by setting the Columns property of the band to the number of columns you want instead of the default of one column and providing a ColumnWidth (note: the dark squares on the designer are 1 wide).

TDBGrid(s) Compare Values and Paint

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.

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.

Need OnCalcFields to be fired on all Rows in dataset Not only just rows visible in DBGrid delphi

I am using Delphi XE5 and FireDAC.
I have a calculated field (Price_Each) and an aggregate field (Total_Price) in a dataset. The aggregate field sums the values of the Calculated Field (Price_Each).
The Dataset is displayed in a Dbgrid, and as there are many rows, some rows of the dataset are outside the Grid view window and need to be scrolled into view.
The issue I am having is that the Aggregate (sum) I get is only for those value of the Price_Each that are displayed in Rows in the DBgrid that are shown. So that Sum is incorrect. When I Scroll the DBGrid to bring the other rows into the View, then the Sum is Updated and then correct.
I want the Sum to be calculated for all rows in the Dataset and not just those rows visible in the DGrid?
The reason why I am using Calculated Fields is that there is some further Logic that I use to calculate the price and I would not be able to do this in an SQL statement that fetches the data.
I there any way to do this?
NOTE: I have already tried setting FetchOptions to fmAll and it did not work. Still I have to scroll the Grid ?

Removing white space in a table

I am having an issue with too much white space. Here's a picture of my data fields with placeholders representing the largest digit count possible in them.
As you can see, after the last "P" the values escape the scope of the chart. While I could increase the size of the table as a whole (currently textwidth), that would be a poor design choice on my part. What I'm thinking is to utilize all of that wasted white space. I don't know what to do though.
When I have all single digit values, the table looks perfect. I want the increased number size to "consume" the white space before forcing the table out of it's defined bounds.
I was hoping using extracolsep with no arguments would remove whitespace, but it sadly does not.
try adding this command before your table;
\renewcommand{\tabcolsep}{1pt}
the default column separator width is 6pt inserted before and after column contents, but this will change that. Replace 1pt with whatever you need.

Resources