zoukankan      html  css  js  c++  java
  • dbgrideh自适应列宽

    DBGridEH自适应宽度
    1.设AutoFitColWidths=true;它的列宽会跟据整个Grid的宽度自动调整且每一列(TColumnEh)都有AutoFitColWidth属性,设为true,该列宽度自动调整,经测试,这种自适应不能满足要求。
    2.OptionsEh中有dghDblClickOptimizeColWidth,当双击表缝时,前一列按当前数据宽度自动调整宽度,这种方式基本上能满足要求,但很不方便。

    3.

    [delphi] view plaincopy
    1. dbgrdh1.AutoFitColWidths:=True;  
    2.   
    3.  for ii:=0 to dbgrdh1.Columns.Count-1 do  
    4.   with dbgrdh1.Columns[ii] do  
    5.   OptimizeWidth;  
    这种方式感觉不错!应该能满足要求。

    4.另外写过程

    [delphi] view plaincopy
    1. function DBGridRecordSize(mColumn: TColumnEh): Boolean;  
    2. { 返回记录数据网格列显示最大宽度是否成功 }  
    3. begin  
    4.   Result := False;  
    5.   if not Assigned(mColumn.Field) then Exit;  
    6.   mColumn.Field.Tag := Max(mColumn.Field.Tag,  
    7.   TDBGridEh(mColumn.Grid).Canvas.TextWidth(mColumn.Field.DisplayText));  
    8.   Result := True;  
    9. end{ DBGridRecordSize }  
    10.   
    11. function DBGridAutoSize(mDBGrid: TDBGridEh; mOffset: Integer =20): Boolean;  
    12. { 返回数据网格自动适应宽度是否成功 }  
    13. var  
    14.   I: Integer;  
    15. begin  
    16.   Result := False;  
    17.   if not Assigned(mDBGrid) then Exit;  
    18.   if not Assigned(mDBGrid.DataSource) then Exit;  
    19.   if not Assigned(mDBGrid.DataSource.DataSet) then Exit;  
    20.   if not mDBGrid.DataSource.DataSet.Active then Exit;  
    21.   for I := 0 to mDBGrid.Columns.Count - 1 do begin  
    22.    if not mDBGrid.Columns[i].Visible then Continue;  
    23.    if Assigned(mDBGrid.Columns[i].Field) then  
    24.      mDBGrid.Columns[i].Width := Max(mDBGrid.Columns[i].Field.Tag,  
    25.        mDBGrid.Canvas.TextWidth(mDBGrid.Columns[i].Title.Caption)) + mOffset  
    26.    else mDBGrid.Columns[i].Width :=  
    27.      mDBGrid.Canvas.TextWidth(mDBGrid.Columns[i].Title.Caption)+ mOffset;  
    28.    //  ShowMsg(IntToStr(mDBGrid.Canvas.TextWidth(mDBGrid.Columns[i].Title.Caption))+'_'+IntToStr( mDBGrid.Columns[i].Width)+mDBGrid.Columns[i].Title.Caption);  
    29.    mDBGrid.Refresh;  
    30.   end;  
    31.   Result := True;  
    32. end{ DBGridAutoSize }  

     

    在DrawColumnCell过程中添加
      DBGridRecordSize(Column)  ;

    在button的click事件中

    BGridAutoSize(dbgrdh1);即可


     



  • 相关阅读:
    编译原理-确定有穷自动机(deterministic finite automata ,DFA)
    编译原理-正规式和正规集
    linux之sed用法
    Linux 中find命令
    运维工作应该掌握哪些技能?
    Last_SQL_Error: Error 'Can't drop database
    关于在centos下安装python3.7.0以上版本时报错ModuleNotFoundError: No module named '_ctypes'的解决办法
    python3.7安装, 解决pip is configured with locations that require TLS/SSL问题
    Linux date命令的用法(转)
    MySQL回滚到某一时刻数据的方法
  • 原文地址:https://www.cnblogs.com/yilongm/p/4745304.html
Copyright © 2011-2022 走看看