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

前端 未结 4 440
我寻月下人不归
我寻月下人不归 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:07

    I think I have found a solution (although it seems a little strange). In order to find the difference between column widths and real width of the DBgrid (that means find the width of the empty space left after last column), we need to keep track of which column is shown on the left now (what is current column that is scrolled to). We can do that using OnDrawColumnCell event, since it will draw only columns which are scrolled on now. Then we need to calculate sum of widths of all visible columns, and subtract that from DBGrid's width. P.S. Sorry for bad english

    Ex code:

         For i:=0 to Last do
         if Vis[i] then
         Begin
          Sum:=Sum+DBG.Columns[i].Width;
          Inc(Cnt);
         End;
    
         if dgColLines in DBG.Options then
         Sum := Sum + Cnt;
    
      //add indicator column width
        if dgIndicator in DBG.Options then
        Sum := Sum + IndicatorWidth;
        Dif:=DBG.ClientWidth - Sum;
    

提交回复
热议问题