How can create summary footer on runtime? - delphi

I use TcxGrid I have create fields on execution time because I have a pivot query and columns are variable
I filled my grid like theese codes
grdCevapDBTableView2.BeginUpdate;
grdCevapDBTableView2.ClearItems;
fillGridView(grdCevapDBTableView2,command);
grdCevapDBTableView2.DataController.CreateAllItems;
grdCevapDBTableView2.EndUpdate;
Now I want to get sum values from these columns. How can create summary footer on runtime?

Say for example you had a field called cost and you wanted to summarise the total:
index := grdCevapDBTableView2.GetColumnByFieldName('cost').index;
grdCevapDBTableView2.Columns[index].Summary.Footerkind:=skSum;
grdCevapDBTableView2.Columns[index].Summary.FooterFormat:='£ #.##';
I would also stick the beginupdate and endupdate between try..finally block, ie:
grdCevapDBTableView2.BeginUpdate;
try
grdCevapDBTableView2.ClearItems;
fillGridView(grdCevapDBTableView2,command);
grdCevapDBTableView2.DataController.CreateAllItems;
finally
grdCevapDBTableView2.EndUpdate;
end;
this just ensures that your tableview will eventually end the update and redraw.

Related

Create an array where the elements are determined by non null values in a row

I have the following sheet to track participation in events...
... that continues for hundreds of columns and rows. A blank cell indicates that person did not participate in that event. I can not change the layout of this sheet.
For each name I need to create an array of Event IDs for the events they have participated in, which would look like this:
Columns would be fine too.
I am already able to generate this array using (pseudo-formula) QUERY(TRANSPOSE(range), "SELECT (Event ID column) WHERE (user column) IS NOT NULL", 0), however I'm looking for a solution that does not need to TRANSPOSE the sheet, either in memory or in a separate 'helper' sheet.
Give a try on below formula.
=FILTER($C$1:$G$1,FILTER($C$3:$G$6,$A$3:$A$6=A8)<>"")

Iterate COUNTIF on a column by pasting form over the column

I would like to iterate the countif form to an entire column with LibreOffice
The form is:
=COUNTIF(P$2:P$5041,R2)
The Table looks like this:
P R
Exp_NotGen_Aha_NotSolved_Recog Exp_Gen_Aha_Solved_Novel
Exp_Gen_NoAha_Solved_Rem Exp_Gen_Aha_Solved_Rem
Base_Gen_NoAha_Solved_Novel Exp_Gen_Aha_Solved_Recog
Exp_Gen_NoAha_Solved_Recog Exp_Gen_Aha_NotSolved_Novel
Exp_Gen_NoAha_NotSolved_Novel Exp_Gen_Aha_NotSolved_Rem
Base_Gen_NoAha_Solved_Recog Exp_Gen_Aha_NotSolved_Recog
Exp_Gen_NoAha_Solved_Rem Exp_Gen_NoAha_Solved_Novel
(...)
So with my form I intent to count up every time I find a name on the column P, which is the same as the name on the column R.
The form returns me the correct number of occurrences (which is e.g 41 on the first line of the column R). But then, when I try to copy and paste the form in order to repeat the calculation for the other rows in R, then I get just blank cells. If i sellect the cell I can see that the form is there (e.g this is what I get when I click over the cell with the result of R2: =COUNTIF(P$2:P$5041,R3) ). But there's no visible output.
Does anybody has any idea why do I get no output?
I know what was the problem. The forms in the sheet weren't being updated. To solve this problem you have to do the following:
Choose Data - Calculate - AutoCalculate (you see a check mark next to the command when AutoCalculate is enabled).
That's it.

do some calculations in a table using dropdowncombo

I have a field in my database called 'Stock'. It displays how many items are there remaining for sale.Now I have a dropdowncombo with values like 1,2,3 etc... So now when I select an item in the grid and click the button SELL I would like the 'Stock' field of the item in question (in the grid) to decrease by the amount that was in the combo. So if the 'stock' was 100 and I sell 5 (dropdowncombo value) I would like the grid value to display now 95. I hope you know what I mean... I could do this with inserting a calculated field but I do not want to. Better an UPDATE ... Any ideas
something like UPDATE MyTable set STOCK = (Mytable.fieldbyname('stock').asInteger - dropdowncombo1.value)
dont have delphi here with me so unsure does this work on selected record in the grid...
abstable1.edit;
abstable.FieldByName('stock').value := abstable.FieldByName('stock').value - strtoint(cxcombobox1.text);
abstable1.Refresh;
This does the job ...

Getting coordinates of an ExcelRange object

In Excel's COM API:
Given an ExcelRange object, how would I determine which rows and columns are contained within it?
I do not want the contents of the range, just the "coordinates" of the range, preferably as integers.
I did notice that ExcelRange has both a Row and a Column property, however these only indicate the row and column of the upper left corner of the range.
Note: I am using Delphi, however this question could be relevant to any language using Excel though COM, so answering using Delphi is not necessary.
Assuming a simple rectangular range then you use the Rows and Columns properties of the ExcelRange object. The top-left of the selection is determined by Range.Row and Range.Column. The number of selected rows and columns is given by Range.Rows.Count and Range.Columns.Count.
In complete generality an Excel range can be made up of multiple non-contiguous areas. In this case you use the Areas property of ExcelRange to iterate through the simple rectangular ranges that make up the complex range.
To illustrate consider the following code:
procedure DescribeExcelRange(const Range: ExcelRange);
var
AreaIndex: Integer;
Area: ExcelRange;
begin
for AreaIndex := 1 to Range.Areas.Count do
begin
Area := Range.Areas[i];
Writeln(Format(
'Area %d: R%dC%d:R%dC%d',
[AreaIndex, Area.Row, Area.Column,
Area.Row+Area.Rows.Count-1, Area.Column+Area.Columns.Count-1]
));
end;
end;
I have not actually tested this code so I hope I have remembered correctly that indexing is 1-based.

Delphi QuantumGrid GetSelectedRowIndex after sorting

I have D2006 and I am using DevExpress QuantumGrid 6 in a project. I am using it in unbound mode. I have several rows and I need to trigger an action when user select a row and click a button. That works fine when the grid is not sorted by user. I use this code to know the row the user has selected:
index := cxMainTable.DataController.GetSelectedRowIndex(0);
cxMainTable.DataController.Values[index, 0];
But when the user sort the grid by clicking in a column header, the index returned is right for the current order displayed but the values the second line returns is the value that you would expect if the grid was not sorted.
Thanks.
You have to distinguish between records and rows.
Maybe TableView.DataController.FocusedRecordIndex is what you want?

Resources