Hello everybody! “Quick Tips” On this I will show how we can read and write text in a “ListView” in a practical and fast.
Let's create a Form (save as uFrmPrincipal) and create it:
* 3 “TLabeledEdit” (EdtCode, EdtDescription, EdtValue);
* 3 “TBitBtn” (BtnSaveRegister, BtnDeleteRegister, BtnLoadRegister);
* 1 “TListView” (ListViewExample).
We will now configure the properties of “ListViewExample”.
Add 3 columns (Code, Description, Value):
Ø Property - ViewStyle = vsReport;
Ø Property - SortType = stText;
We can see the complete example:
Unit’s Implementation:
unit uFrmPrincipal;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, ComCtrls, Buttons;
type
TFrmPrincipal = class(TForm)
EdtCode: TLabeledEdit;
EdtDescription: TLabeledEdit;
EdtValue: TLabeledEdit;
Panel1: TPanel;
ListViewExemplo: TListView;
BtnSaveRegister: TBitBtn;
BtnDeleteRegister: TBitBtn;
BtnLoadRegister: TBitBtn;
procedure BtnSaveRegisterClick(Sender: TObject);
procedure BtnDeleteRegisterClick(Sender: TObject);
procedure BtnLoadRegisterClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
FrmPrincipal: TFrmPrincipal;
implementation
{$R *.dfm}
{Save Register in the ListView}
procedure TFrmPrincipal.BtnSaveRegisterClick(Sender: TObject);
Var
Item: TListItem;
begin
Item := ListViewExample.Items.Add;
Item.Caption := EdtCode.Text;
Item.SubItems.Add(EdtDescription.Text);
Item.SubItems.Add(EdtValuer.Text);
EdtCode.Clear;
EdtDescription.Clear;
EdtValue.Clear;
end;
{Delete Register of the ListView}
procedure TFrmPrincipal.BtnDeleteRegisterClick(Sender: TObject);
begin
if ListViewExample.ItemIndex >= 0 then
ListViewExample.DeleteSelected
else
ShowMessage('Select an item to delete');
end;
{Load Register of the ListView}
procedure TFrmPrincipal.BtnLoadRegisterClick(Sender: TObject);
begin
if ListViewExample.ItemIndex >= 0 then
begin
EdtCode.Text := ListViewExample.ItemFocused.Caption;
EdtDescription.Text := ListViewExample.ItemFocused.SubItems[0];
EdtValue.Text := ListViewExample.ItemFocused.SubItems[1];
end
else
ShowMessage('Could not select any item to load');
end;
end.
Until next Quick Tips.
Wesley Y
wyamazack@rwsolution.com.br
'Academy I > Tech Academy' 카테고리의 다른 글
[Delphi]10.3 버전의 EULA (0) | 2019.06.27 |
---|---|
[Delphi]커뮤니티 에디션 (0) | 2019.06.27 |
[Delphi]Skin Components (0) | 2019.06.19 |
[Delphi]크롬 브라우저를 특정 URL로 띄우기 (0) | 2019.05.16 |
[Delphi]Save to Internet Image (0) | 2019.03.06 |
[Delphi]글자가 한글인지 확인 (0) | 2019.03.06 |
[Delphi]Pointer (0) | 2019.02.20 |
[Delphi]인터넷 연결 상태 확인 (0) | 2019.01.31 |