zoukankan      html  css  js  c++  java
  • 使用 TListView 控件(3)


    本例效果图:



    代码文件:
    unit Unit1;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ComCtrls;
    
    type
      TForm1 = class(TForm)
        ListView1: TListView;
        Button1: TButton;
        Button2: TButton;
        CheckBox1: TCheckBox;
        CheckBox2: TCheckBox;
        procedure FormCreate(Sender: TObject);
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
        procedure CheckBox1Click(Sender: TObject);
        procedure CheckBox2Click(Sender: TObject);
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    procedure TForm1.FormCreate(Sender: TObject);
    var
      i: Integer;
      column: TListColumn;
    begin
      for i := 0 to 5 do
      begin
        column := ListView1.Columns.Add;
        column.Caption := Format('Col %d', [i]);
      end;
    
      ListView1.Align := alTop;
      ListView1.ViewStyle := vsReport;
      ListView1.GridLines := True;         {非默认}
      ListView1.ShowColumnHeaders := True; {默认}
      CheckBox1.Caption := 'GridLines';
      CheckBox2.Caption := 'ShowColumnHeaders';
      CheckBox1.Checked := True;
      CheckBox2.Checked := True;
      Button1.Caption := '添加';
      Button2.Caption := '清空';
    end;
    
    procedure TForm1.Button1Click(Sender: TObject);
    var
      item: TListItem;
      i: Integer;
    begin
      item := ListView1.Items.Add;
      item.Caption := 'Item ' + IntToStr(item.Index);
    
      for i := 0 to ListView1.Columns.Count - 1 do
        item.SubItems.Add(Format('%d%d', [item.Index, i]));
    end;
    
    procedure TForm1.Button2Click(Sender: TObject);
    begin
      ListView1.Items.Clear;
    end;
    
    procedure TForm1.CheckBox1Click(Sender: TObject);
    begin
      ListView1.GridLines := CheckBox1.Checked;
    end;
    
    procedure TForm1.CheckBox2Click(Sender: TObject);
    begin
      ListView1.ShowColumnHeaders := CheckBox2.Checked;
    end;
    
    end.
    

    窗体文件:
    object Form1: TForm1
      Left = 0
      Top = 0
      Caption = 'Form1'
      ClientHeight = 198
      ClientWidth = 322
      Color = clBtnFace
      Font.Charset = DEFAULT_CHARSET
      Font.Color = clWindowText
      Font.Height = -11
      Font.Name = 'Tahoma'
      Font.Style = []
      OldCreateOrder = False
      OnCreate = FormCreate
      PixelsPerInch = 96
      TextHeight = 13
      object ListView1: TListView
        Left = 8
        Top = 8
        Width = 185
        Height = 121
        Columns = <>
        TabOrder = 0
      end
      object Button1: TButton
        Left = 232
        Top = 134
        Width = 75
        Height = 25
        Caption = 'Button1'
        TabOrder = 1
        OnClick = Button1Click
      end
      object Button2: TButton
        Left = 232
        Top = 165
        Width = 75
        Height = 25
        Caption = 'Button2'
        TabOrder = 2
        OnClick = Button2Click
      end
      object CheckBox1: TCheckBox
        Left = 16
        Top = 145
        Width = 97
        Height = 17
        Caption = 'CheckBox1'
        TabOrder = 3
        OnClick = CheckBox1Click
      end
      object CheckBox2: TCheckBox
        Left = 16
        Top = 169
        Width = 177
        Height = 17
        Caption = 'CheckBox2'
        TabOrder = 4
        OnClick = CheckBox2Click
      end
    end
    
  • 相关阅读:
    截取url中最后斜杆的文件名
    html span从上往下,从左往右排序
    浪漫源码记录
    微信小程序TypeError: Cannot read property 'elem' of undefined
    tomcat8 性能优化
    Bandicam神奇使用法
    DataStage 七、在DS中使用配置文件分配资源
    DataStage 六、安装和部署集群环境
    DataStage 错误集(持续更新)
    DataStage 三、配置ODBC
  • 原文地址:https://www.cnblogs.com/del/p/1368342.html
Copyright © 2011-2022 走看看