Have cxGrid expand current date

ぐ巨炮叔叔 提交于 2019-12-11 09:48:29

问题


I made my grid group by date (grabbed the column name and dragged it to where it says 'group by that column'). However, when the grid is displayed all the dates are 'closed' so I must expand them to see data. That is OK but I wonder if it is possible to have current date expanded already (all other should remain closed !) so I do not have to click the expand cross?


回答1:


try this, you can put the code in other event handler like a TButton for example

procedure TForm1.FormCreate(Sender: TObject);
begin
    //aDBTableView1.ViewData.Expand(true);            // this is how to expand all records 
    aDBTableView1.ViewData.Records[YourRecordNumber].Expand(true);   // this is how to expand by a given record
end;

OK try the following

procedure TForm1.FormCreate(Sender: TObject);
begin
  with cxGrid1DBTableView1 do
  begin
    DataController.DataSource.DataSet.Locate('YourDateFieldName',DateTimeToStr(Date),
    [loPartialKey]);
    ViewData.Records[DataController.FocusedRowIndex].Expand(True);
  end;
end;



回答2:


procedure TForm1.Button1Click(Sender: TObject);
var
  intLoop,
  vValue: Variant;
begin
  for intLoop := 0 to self.cxGrid1DBTableView1.DataController.RowCount - 1 do
  begin
    if self.cxGrid1DBTableView1.ViewData.Rows[IntLoop] is TcxGridGroupRow then
    begin
      if TcxGridGroupRow(cxGrid1DBTableView1.ViewData.Rows[IntLoop]).Level = cxGrid1DBTableView1MyDate.GroupIndex  then
      begin
        vValue:=TcxGridGroupRow(cxGrid1DBTableView1.ViewData.Rows[IntLoop]).Value ;
        if vValue = Date() then
        begin
          TcxGridGroupRow(cxGrid1DBTableView1.ViewData.Rows[intLoop]).Expand(False);
        end;
      end;
    end;
  end;
end;


来源:https://stackoverflow.com/questions/15304898/have-cxgrid-expand-current-date

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!