We help IT Professionals succeed at work.

Enter data in a listview

Peter Kiers
Peter Kiers used Ask the Experts™
on
Hi,

I have an inputform call frmInsItem with a Edit-field edtProdName on it
and an Inser-button and a Close-button. And a listview on the main form.

What I would like is when a user enters data in the edit field edtProdName
and presses the Insert-button. The data will be entered in the column Product Name
of the listview on the main form.

Who can help me?

P.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
I hope that helps;
Just input 1Listview, 1Button, 2EditBox;
unit Unit1;

interface

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

type
  TForm1 = class(TForm)

    Edit1: TEdit;
    Edit2: TEdit;
    ListView1: TListView;
    Button1: TButton;

    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;


implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var NewItem: TListItem;
begin
NewItem := ListView1.Items.Add;
NewItem.Caption:=Edit1.Text;
NewItem.subitems.Add(Edit2.Text);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
with ListView1 do
begin
Columns.Add;
Columns.Add;
ViewStyle:=vsreport;
GridLines:=true;
rowselect := true;
columns.items[0].caption:='Product ID';
columns.items[1].caption:='Product Name';
Columns.Items[0].Width:=90;
Columns.Items[1].Width:=290;
end;
ListView1.Items.Clear;
end;

end.

Open in new window

Peter KiersOperator

Author

Commented:
Thanks. P.