Free Online Courses for Software Developers - MrBool
× Please, log in to give us a feedback. Click here to login
×

You must be logged to download. Click here to login

×

MrBool is totally free and you can help us to help the Developers Community around the world

Yes, I'd like to help the MrBool and the Developers Community before download

No, I'd like to download without make the donation

×

MrBool is totally free and you can help us to help the Developers Community around the world

Yes, I'd like to help the MrBool and the Developers Community before download

No, I'd like to download without make the donation

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



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 Brazi...

What did you think of this post?
Services
[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
[Close]
You must be logged to download.

Click here to login