2

In cxGrid,I have a column that is boolean (properties : checkbox). How can I do a footer summary (SUM) of such a column i.e to sum how many records are checked.

Right now, if I set it to SUM, my footer summary displays negative numbers for the items checked.How can I avoid these negative numbers?

edit : I have found a would be solution on their site with :

procedure TForm1.cxGrid1DBTableView1DataControllerSummaryFooterSummaryItemsSummary(
  ASender: TcxDataSummaryItems; Arguments: TcxSummaryEventArguments;
  var OutArguments: TcxSummaryEventOutArguments);
var
  si: TcxGridDBTableSummaryItem;
begin
  si := Arguments.SummaryItem as TcxGridDBTableSummaryItem;
  if si.Column = cxGrid1DBTableView1Sonda then
    OutArguments.Done := not OutArguments.Value;
end;

However I am getting the error : Could not convert variant of type (Null) into type (Boolean).

Dont understand this. Field is boolean type (bit).

edit2:

The problem is that sql server by default sets boolean type to NULL. That is why the conversion error.

user763539
  • 3,509
  • 6
  • 44
  • 103

5 Answers5

2

You can also just set your grid to calculate that summary using a different field , for example a calculated field where you assign the exact value you want to add each time.

  • Add a calculated field to your dataset, with the desired value. MyHiddenField.Value := -1 * YourCheckingField.AsInteger;

  • Go to the Summaries Tab on the CxGrid dialog, and add a new Summary:

    1. Set the Column property to the Grid Column where you want it to appear
    2. Set the FieldName to your calculated field
    3. And finally set Kind to skSum
Marc Guillot
  • 6,090
  • 1
  • 15
  • 42
1

It is better to send such questions to DevExpress support team. You can customize footer:

  • assign Kind=skNone to footer summary item
  • use OnGetText event to show what you want

Quick example (shows number of chars in all records as footer value):

procedure TForm54.cxGrid1DBTableView1TcxGridDBDataControllerTcxDataSummaryFooterSummaryItems0GetText(
  Sender: TcxDataSummaryItem; const AValue: Variant; AIsFooter: Boolean;
  var AText: string);
var i,j: integer;
begin
  j := 0;
  for i := 0 to cxGrid1DBTableView1.DataController.RecordCount-1 do
    j := j + Length(String(cxGrid1DBTableView1.DataController.Values[i, cxGrid1DBTableView1c.Index]));
  AText := IntToStr(j);
end;
Andrei Galatyn
  • 3,322
  • 2
  • 24
  • 38
0

I think that you can resolve that problem in SQL component. Use typecasting and your cxGrid will work with Integer values.

SELECT CAS(Bit_Column AS int) AS Int_Column
FROM YourTable
mikia
  • 454
  • 1
  • 4
  • 14
0

You can try this :

procedure TForm1.cxGrid1DBTableView1DataControllerSummaryAfterSummary(
  ASender: TcxDataSummary);
var i, j, Imp:integer;
    Item: TcxGridDBTableSummaryItem;
begin
  DBTableView1.DataController.BeginLocate;
  for j:=0 to ASender.FooterSummaryItems.Count-1 do ASender.FooterSummaryValues[j]:=0;
  try
    for i:=0 to DBTableView1.DataController.RowCount-1 do
    begin
      if (DBTableView1.DataController.Values[i,cxGrid1DBTableView1Sonda.Index]<>null) then
        for j:=0 to ASender.FooterSummaryItems.Count-1 do
        begin
          Item:=TcxGridDBTableSummaryItem(ASender.FooterSummaryItems[j]);
          Imp:= DBTableView1.DataController.Values[i, cxGrid1DBTableView1Sonda.Index];
          if (Imp= 1) or ((Imp= 2) 
          then ASender.FooterSummaryValues[j]:= ASender.FooterSummaryValues[j]+1;
        end;
    end;
  finally
    DBTableView1.DataController.EndLocate;
  end;
end;
MSB
  • 181
  • 1
  • 2
  • 9
0
procedure cxGrid1DBTableView1DataControllerSummaryFooterSummaryItemsSummary(
  ASender: TcxDataSummaryItems; Arguments: TcxSummaryEventArguments;
  var OutArguments: TcxSummaryEventOutArguments);

    var
      AValue: Variant;
      AItem: TcxGridTableSummaryItem;
    begin
      AItem := TcxGridTableSummaryItem(Arguments.SummaryItem);

      // считаем проверенные
      if (AItem.Column = tvCompareisCorrect) and (AItem.Kind = skCount) and (AItem.Position = spFooter) then begin
        AValue := tvCompare.DataController.Values[ Arguments.RecordIndex, tvCompareisCorrect.Index];
        if not VarIsNull(AValue) then
          if not VarAsType(AValue, varBoolean) then Dec(OutArguments.CountValue);
      end;