Login:  Password:    
forgot my password
sign up!
Search: 

Read and Write: ListView in Delphi

On this I will show how we can read and write text in a “ListView” in a practical and fast.


 

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 and 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





Add a comment!
[Fechar]

Este post é fechado - vocę precisa ter acesso ao post para incluir um comentário.


No comment was posted yet - be the first!



 
Help us to improve! Give us your feedback:
Give your note to the technical content
10 9 8 7 6 5 4 3 2 1
Give your note to the post's learning
10 9 8 7 6 5 4 3 2 1
Is this post helpful?
Yes No


Wesley Yamazack Batista
Graduated in System Analysis, in business development for over six years, where he worked in companies of various segments such as financial, commercial, parking, etc.. He is currently a third-party developer analyst Navy of Brazil, and to develop pa...


Go to author's Space


Post stats:
Favorited:
 1

Post actions:
[Close]
To have full access to this post (or download the associated files) you must have MrBool Credits.

  See the prices for this post in Mr.Bool Credits System below:

Individually – in this case the price for this post is US$ 0,00 (Buy it now)
in this case you will buy only this video by paying the full price with no discount.

Package of 10 credits - in this case the price for this post is US$ 0,00
This subscription is ideal if you want to download few videos. In this plan you will receive a discount of 50% in each video. Subscribe for this package!

Package of 50 credits – in this case the price for this post is US$ 0,00
This subscription is ideal if you want to download several videos. In this plan you will receive a discount of 83% in each video. Subscribe for this package!


> More info about MrBool Credits








mrbool.com
contact us   |   publish your post   |   buy credits

Copyright 2012 - all rights reserved to www.web-03.net