给100分。问题。当ListView中某一列的内容,超过这一列的宽度时。
显示的内容不全就像这样:"2003-4-.."
还有一个数字没有显示出来。我想在程序中,让他自动列宽怎么做啊?在线等待。
答对马上给分?我试过几次方法都不行。

解决方案 »

  1.   

    得到某列中所有内容中,内容最长的宽度(内容本身的宽度)
    如:"1234567890" length后。宽度是10
    再*6
    这一列的宽度就是60
    还是不行。为什么要*6
    我试了一下。
    LAbel.width:=0;
    LABEL.caption:='0';//一个英文字。
    showmessage(inttostr(label.width));
    显示为6;
      

  2.   


    我看了你的方法,应该可以的。
    加上 ListView1.Repaint试试就是重画一下。
      

  3.   

    不行。。看看我的代码。
    有没有哪里不对的地方!procedure AutoListVWidth(ListV : TlistView);
    var
      i,j,tmpWidth,tmpWidth1,titleWidth :integer;
    begin
      For j:=0 to ListV.Columns.count-1 do begin
          tmpWidth1:=0;
          TitleWidth:=Length(ListV.Columns.Items[j].Caption)*6;
          For i:=0 to ListV.Items.Count-1 do begin
            IF j=0 then begin
              tmpWidth:=Length(ListV.Items.Item[i].Caption)*6;
              IF TmpWidth>tmpWidth1 then tmpWidth1:=tmpWidth;
            End
            Else begin
              tmpWidth:=Length(ListV.Items.Item[i].subitems.strings[j-1])*6;
              IF TmpWidth>tmpWidth1 then tmpWidth1:=tmpWidth;
            End;
          End;
          IF tmpWidth1>TitleWidth then ListV.Columns.items[j].Width:=TmpWidth1
          Else ListV.Columns.items[j].Width:=TitleWidth;
          ListV.Repaint;
      End;
    end;
      

  4.   

    Use Width to specify the width of the list column, in pixels. If Width is assigned the value -1, the list column is automatically resized to accommodate the text in the column. //如果你想那个列的宽度自动适应大小,只要把它设置为-1,就可以了。
      

  5.   

    打印的时候。我现在用的是-2又怎么能得到他的真实WIDTH??
      

  6.   

    没有在打印机上作过,不过可以提供两个函数参考。
    1。 canvas.textwidth : 返回指定字符串的宽度(像素)。
    2。 getdevicecap: 返回指定输出设备的信息。
    这两个函数能够比较准确的计算各种输出的尺寸。