Search code examples
delphidevexpressdelphi-xe7tcxgrid

cxgrid expand grouped data using cxDateEdit


My displayed data in the cxGrid is grouped by date (collapsed) . Is there a way I can expand this grouped data "only" for a selected date using cxDateEdit for the occasion ?

Right now,all I could manage is to collapes or expand all data using buttons:

procedure TArchive.EXPANDClick(Sender: TObject);
begin
cxGrid1DBTableView1.ViewData.Expand(True);
end;


procedure TArchive.COLLAPSEClick(Sender: TObject);
begin
cxGrid1DBTableView1.ViewData.Collapse(True);
end;

I would like to expand the records only for the date displayed in the cxDateEdit. And possibly display a message if no data for the desired date was found.

Edit : I have found a way to do this :

procedure TARCHIVE.cxDateEdit1PropertiesChange(Sender: TObject);
begin
with cxGrid1DBTableView1 do
  begin
    DataController.DataSource.DataSet.Locate('FOR_DATE',cxDateEdit1.Date,
    [loPartialKey]);
    ViewData.Records[DataController.FocusedRowIndex].Expand(True);
end;
end;

However I cant figure out how to flash a message if the date displayed in the cdDateEdit does not exist in the cxGrid.


Solution

  • Got it :

        procedure TARCHIVE.cxDateEdit1PropertiesChange(Sender: TObject);
        begin
        with cxGrid1DBTableView1 do
        begin
        if   DataController.DataSource.DataSet.Locate('FOR_DATE',cxDateEdit1.Date,
            [loPartialKey]) then begin
            ViewData.Records[DataController.FocusedRowIndex].Expand(True);
        end else begin
        ShowMessage('No entries for desired date.');
        end;
        end;
        end;