How to find the actual width of grid component with scrollbar in Delphi

前端 未结 4 434
我寻月下人不归
我寻月下人不归 2020-12-20 03:46

I have a grid component (DBGrid) which has lots of columns on it. Because of large number of columns, a scrollbar was created, and thus some part of grid remains hidden. I n

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-20 04:17

    TDBGrid has a Columns property. Each of the columns has its own Width property. So you could loop through all of the columns and sum up their widths.

    Like this:

    function TotalColumnsWidth(var AGrid: TDBGrid);
    var
      i: Integer;
    begin
      Result := 0;
      for i := to AGrid.Columns.Count - 1 do
        Result := Result + AGrid.Columns[i].Width;
    end;
    

提交回复
热议问题