[Latest][6]

Delphi
DIY

Login

Enter your username and password to enter your Blogger Dasboard


Featured Post

Power resistor DIY

Power resistor DIY This is one simple way to create power resistor at home. I needed 0,33 ohm resistor with some larger wattage so I de...

Recent Articles

Powered By Blogger

Wednesday, March 30, 2016

Delphi Tutorial Listview

kobyx     12:53 PM     0

Delphi Tutorial Listview

In this tutorial you can learn how to work with Listview in Delphi.
You can learn how to create,edit and delete items, and also how to add icons to items.

Here is video with steps :



Here is also code used in this video :

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ImgList, Menus, StdCtrls, ExtCtrls, ComCtrls;

type
  TForm1 = class(TForm)
    ListView1: TListView;
    Panel1: TPanel;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    Button5: TButton;
    CheckBox1: TCheckBox;
    Button6: TButton;
    Button7: TButton;
    Button8: TButton;
    Button9: TButton;
    ImageList1: TImageList;
    Button10: TButton;
    CheckBox2: TCheckBox;
    procedure Button1Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure Button7Click(Sender: TObject);
    procedure Button8Click(Sender: TObject);
    procedure Button9Click(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure ListView1DblClick(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button10Click(Sender: TObject);
    procedure CheckBox2Click(Sender: TObject);
    procedure ListView1Edited(Sender: TObject; Item: TListItem; var S: string);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button10Click(Sender: TObject);
var
Itm:TListItem;
i:Integer;
begin
for I := 1 to 10 do
begin
Itm:=ListView1.Items.Add;

Itm.Caption:='Item '+IntToStr(ListView1.Items.Count);
Itm.SubItems.Add(Itm.Caption+' Subitem 1');
Itm.SubItems.Add(Itm.Caption+' Subitem 2');
Itm.ImageIndex:=0;
end;


end;

procedure TForm1.Button1Click(Sender: TObject);
var
Itm:TListItem;
begin
Itm:=ListView1.Items.Add;
Itm.Caption:='Item '+IntToStr(ListView1.Items.Count);
Itm.SubItems.Add(Itm.Caption+' Subitem 1');
Itm.SubItems.Add(Itm.Caption+' Subitem 2');

Itm.ImageIndex:=0;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
ListView1.DeleteSelected;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
ListView1.Items.Clear;
end;

procedure TForm1.Button4Click(Sender: TObject);
var i:Integer;
begin
for I := 0 to ListView1.Items.Count-1 do
begin
ListView1.Items[i].Checked:=True;
end;
end;

procedure TForm1.Button5Click(Sender: TObject);
var i:Integer;
begin
for I := 0 to ListView1.Items.Count-1 do
begin
ListView1.Items[i].Checked:=False;
end;
end;

procedure TForm1.Button6Click(Sender: TObject);
begin
ListView1.ViewStyle:=vsIcon;
end;

procedure TForm1.Button7Click(Sender: TObject);
begin
ListView1.ViewStyle:=vsList;
end;

procedure TForm1.Button8Click(Sender: TObject);
begin
ListView1.ViewStyle:=vsReport;
end;

procedure TForm1.Button9Click(Sender: TObject);
begin
ListView1.ViewStyle:=vsSmallIcon;
end;

procedure TForm1.CheckBox1Click(Sender: TObject);
begin
  ListView1.Checkboxes:=CheckBox1.Checked;
end;

procedure TForm1.CheckBox2Click(Sender: TObject);
begin
ListView1.RowSelect:=CheckBox2.Checked;
end;

procedure TForm1.ListView1DblClick(Sender: TObject);
begin
if ListView1.ItemFocused.Checked=true then
 ListView1.ItemFocused.Checked:=false
else
  ListView1.ItemFocused.Checked:=True;
end;

procedure TForm1.ListView1Edited(Sender: TObject; Item: TListItem;
  var S: string);
begin
 Item.SubItems[0]:=
S+' Subitem 1';
Item.SubItems[1]:=
S+' Subitem 2';
end;

end.

Author: kobyx

Hello, I am Author,thank you for reading.Please comment, and let me know what you think about this post.

0 comments:

Comments

© 2014 Tutorials. Designed by Bloggertheme9. Powered by Blogger.