• 使用 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
    
  • 相关阅读:
    自适应高度的 文本框
    点击小图片遮罩显示大图片
    C++中的声明与定义
    LeetCode_Bit Manipulation
    “纯”面向对象
    指针和引用
    new和delete用法小结
    C++中的变量属性小结
    C++的一些黑暗料理
    Python中的字典和集合
  • 原文地址:https://www.cnblogs.com/del/p/1368342.html
Copyright © 2020-2023  润新知