Fundamental Questions on Grid

Hi there...


I am having a hard time with Firemonkey. I think my brain is strong wired for VCL....

I read part of the documentation, and looked at the demos but some questions remain:

  1. It seems that there is no much to be done visually, it is all by code: col width, col position, formating, etc. Is this right? or am I missing some place where can I change the properties of the column ?
  2. I am using livebinding and I see that when I bind the BindSource all the columns are created, but my table have many column, I need few and in a different order that comes from the database. Does it need to be done by code?
  3. I have 31 columns, and need to keep 10 on the grid, Do i need to count each one to find out the number?
  4. How can I see all the columns? Horizontal Scroll does not work on design time.

Thank you 

Eduardo

adding to the above...


I am using XE6.

I have looked to the livebinding demo and could see that on the binding component you can create only the columns needed. However it is complex, is there a simplier way? there is many values to be defined for each single column on that binding editor. Is that correct? In this case by code should be "easier".

On problem that I am having is that I use Aurelius and many properties from the datasource are pointers to objects, and all that get imported as columns. Then I need to create even more properties to display the values requeried, turning a single table in a buch of fields that needs to be hidden.

Thanks

The LiveBindings implementation in the grid is not able to configure the number of columns that are displayed. This has to be configured in the link to the datasource. In the LiveBindings demo you can configure this in the LinkGridToDataSource1 component that is automatically generated when connecting the dataset to the grid. If you select the LinkGridToDataSource1 component in the structure pane and right-click it, you will be able to click "columns editor". the columns editor allows you to select which columns are displayed and in which order.


Kind Regards, 
Pieter

Amazing... It needs to have a big red button somewhere to point to this place !!!!


Now another question... I need to get a form done using this grid, please help me....

I have added 2 column using the livebinding and using the editor.

On the code side I have done this:

  GridItens.Options.Grouping.MergeHeader := true;
  GridItens.Options.Grouping.Summary := true;

  GridItens.Group(1);

That is the column "date" 

The problem now is that my Date field is actually a TDateTime. And I need only the TDate part. Is it possible to be extracted for grouping?


Hi, 


Grouping in combination with LiveBindings is not possible while LiveBindings is still active. You will need to deactivate the DataSet and set the flag to save the data: 

TMSFMXGrid1.SaveDataSetData := True.
DataSet1.Active := False.

Afterwards you can override the OnGetCellData and return:

procedure TForm80.TMSFMXGrid1GetCellData(Sender: TObject; ACol, ARow: Integer;
  var CellString: string);
var
  dt: TDateTime;
begin
  if (ACol = 1) and (CellString <> '') then //date column
  begin
    dt := StrToDateTime(CellString);
    CellString := DateToStr(int(dt));
  end;
end;

Kind Regards, 
Pieter

Ok , in this case SaveDataSetData will kill the entire data in memory right?


Can I group in more than one level? 

group 1 - date column
group 2 - name column

Eduardo

When setting SaveDataSetData, the data will be saved in inside the grid. Setting SaveDataSetData to true prevents the grid from being cleared after dataset changes to non-active. 


It is currently not possible to group on more than one column.
When starting a group operation on a second column, the grid first performs an ungrouping operation.

Kind Regards, 
Pieter

Pieter, thank you a lot, I am almost getting the grid in the way needed. I lost a lot of days with the firemonkey grid with no success. I am trying to get the time back with TMS grid and hopefully present today a version of the software with it.


Question:

1) GridItens.Columns.Items[ACol].Name  does not bring the name of the column. Is there a way to use the livebinding name to address the columns? I would prefer to stick with the name of the dataset field than a column number.

2) how can i get total in grouping? grouping is now working as expected! I have a column that is "Total" and I need that in the summary shows it calculated (SUM)

Thanks

Eduardo

Pieter, 


There is a strange thing happening with grouping:

After I apply the grouping the widths that I set for the columns are wrong. It is like it shifted 1 column, because the first column is now the grouping column.

How can I prevent this?

Eduardo
This is before grouping: http://snag.gy/Pw30N.jpg

After Grouping: http://snag.gy/O8GNj.jpg


1) Only the column index is passed as a parameter, but you can access the columns in the LinkGridToDataSource1 component with the following code: LinkGridToDataSource1.Columns[ACol - 1].MemberName. Note that you have to substract 1 (or fixed columns) because ACol has included the FixedColumn property.
 
2) To bring up the sum of a specific column you can use the following code:
TMSFMXGrid1.GroupSum(Col);

About the column widths, we will have to investigate here what is going wrong, but to fix this, you can easily change the column widths after grouping with TMSFMXGrid1.ColumnWidths[Col] := 

Kind Regards, 
Pieter



Pieter


The only last thing needed and I am done with this grid, I will be using the same concept over all the software:

  GridItens.Options.Grouping.MergeHeader := true;
  GridItens.Options.Grouping.Summary := true;

  GridItens.SaveDataSetData := true;

  bsdbPDVCaixaItemExcluido.DataSet.Active := false;

  GridItens.Group(1);
  GridItens.GroupSum(4);

This last command, groupsum is not getting the SUM of this column, it is blank.

This is a money column with values like R$ 10,00

but even removing the money sign it is not calculating.

What can it be?

The money value is interpreted in your data as a string, which is not valid for calculating the sum of all the values for each group. You will need to change the column type to a double so only the floating value is inserted in the grid. You can always apply money formatting afterwards.


Kind Regards, 
Pieter

Ok, but on TAureliusDataSet it is defined as a ftCurrency field already.


I have changed to Extended and made no changed.

I have also commented out the GridItensGetCellData event:

  if ARow > 0 then
    if (ACol = 4) or (ACol = 5) then
      CellString := CurrToStrF(StrToCurrDef(CellString, 0), ffCurrency, 2);

so there is not formating. And on summary there is no SUM of the column. Is it necessary anything else?

Thanks

As an alternative you could verify the contents of TMSFMXGrid1.Floats[ACol, ARow] and verify if this contains the values you would expect. The sum calculations of the grid rely on this property. Perhaps you could also take a look at the grouping demo which demonstrates how to apply a sum row for each group.


Kind Regards, 
Pieter

I have changed to this:


  if ARow > 0 then
    if (ACol = 4) or (ACol = 5) then
    begin
      CellString := CurrToStrF(GridItens.Floats[ACol, ARow] , ffCurrency, 2);
    end;

And Floats is most of the time with zero. Just in few cases has a value, and that is very strange.

Adding a breakpoint in the entity i can see that TMS Grid is looking for data AFTER this event. So it gets all the data at first moment as string, firing this event, and then goes all the records again, and in this case getting the values, but the values not going to Floats.

I took a look on all the demos already, specially the group demo, but some details are not explicit.

thanks

I have tried this:


      GridItens.Floats[ACol, ARow] := StrToCurrDef(CellString, 0);
      CellString := CurrToStrF(StrToCurrDef(CellString, 0), ffCurrency, 2);

doing the inverse order and define the Floats. Does not work.

Is this column expecting one specific format? I have tried ftFloat and ftExtended on the DataSet (TAureliusDataSet) with not success.

It loads as string. 

Is there a way I can set this value manually and make it recalculate?
After setting the dataset to false you could loop the rows for the column 5 (index 4)  

 bsdbPDVCaixaItemExcluido.DataSet.Active := false;

//loop the cell values and add them as float values

  GridItens.Group(1);
  GridItens.GroupSum(4);

I did this:


  GridItens.Options.Grouping.MergeHeader := true;
  GridItens.Options.Grouping.Summary := true;

  GridItens.SaveDataSetData := true;

  bsdbPDVCaixaItemExcluido.DataSet.Active := false;

  GridItens.Group(1);
  GridItens.GroupSum(4);

  for i := 1 to GridItens.RowCount - 1 do
    GridItens.Floats[4, i] := StrToFloatDef(GridItens.Cells[4, i], 0);


and does not work. I have tried assigning the Floats before grouping and either does not work.

I am no formating the money column anymore, so I can have the value for use. 

Any ideas? basically this is the last thing for me.

Note that the Floats before grouping are at column index 5 instead of 4.

Grouping removes a column to create node headers and all indexes are shifted by one.
Setting the Floats after creating a sum will not have any effect, so applying this on your code, it should similar to the code below:

  GridItens.Options.Grouping.MergeHeader := true;
  GridItens.Options.Grouping.Summary := true;

  GridItens.SaveDataSetData := true;

  bsdbPDVCaixaItemExcluido.DataSet.Active := false;

  for i := 1 to GridItens.RowCount - 1 do
    GridItens.Floats[5, i] := StrToFloatDef(GridItens.Cells[5, i], 0);

  GridItens.Group(1);
  GridItens.GroupSum(4);