如何确定cxGrid网格数据的高度

2021-01-31

procedure SetGridHeight(AGrid: TcxGrid; ARowsNumber: Integer);  

var  

  I: Integer;  

  AHeight: Integer;  

begin  

  if (AGrid = nil) or (AGrid.FocusedView = nil) then  

    Exit;  

  AHeight := 0;  

  with AGrid.FocusedView as TcxGridDBTableView do  

  begin  

    ViewData.Collapse(True);  

    with ViewInfo do  

    begin  

      for I := 0 to ARowsNumber - 1 do  

      begin  

        Inc(AHeight, RecordsViewInfo.Items[I].DataHeight);  

        if I < ARowsNumber - 1 then  

          Inc(AHeight, GridLineWidth);  

      end;  

      if OptionsView.GroupByBox then  

        Inc(AHeight, GroupByBoxViewInfo.Height);  

      Inc(AHeight, HeaderViewInfo.Bounds.Bottom - HeaderViewInfo.Bounds.Top);  

    end;  

    Inc(AHeight, GetSystemMetrics(SM_CYHSCROLL));  

    AGrid.Height := AHeight;  

  end;  

end;  


阅读169