| | |
Storing an Integer with each row in a TListView?
Please support our Pascal and Delphi advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jan 2009
Posts: 2
Reputation:
Solved Threads: 0
Hey,
Is there an easy way with a TListView in report mode, to store a unique integer with each row? I've tried using the ".Data" property, but seem to end up with corruption quite often.
I'm trying to do this because I want to associate each row with a primary key ID from a database. At the moment I'm using a dynamically sized array, and adding the row id, to the db ID so I have to use, for example, rowsToIds[lv.SelectedIndex]; but it seems like a long-winded way to do it.
Is there an easier way to do this? Simple example of exactly what I'm trying to do...
Thanks
Is there an easy way with a TListView in report mode, to store a unique integer with each row? I've tried using the ".Data" property, but seem to end up with corruption quite often.
I'm trying to do this because I want to associate each row with a primary key ID from a database. At the moment I'm using a dynamically sized array, and adding the row id, to the db ID so I have to use, for example, rowsToIds[lv.SelectedIndex]; but it seems like a long-winded way to do it.
Is there an easier way to do this? Simple example of exactly what I'm trying to do...
Pascal and Delphi Syntax (Toggle Plain Text)
procedure TForm1.FormCreate(Sender: TObject); var i: Integer; li: TListItem; begin for i := 0 to 50 do begin li := lv1.Items.Add; li.Caption := 'xyz'; li.SubItems.Add('abc'); //Store a unique integer with the row here... end; end; procedure TForm1.lv1DblClick(Sender: TObject); begin //Show the stored integer here... end;
Thanks
•
•
Join Date: Oct 2009
Posts: 10
Reputation:
Solved Threads: 4
0
#3 Oct 30th, 2009
unit IntObject;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs,
ComCtrls;
type
TForm1 = class(TForm)
ListView1: TListView;
procedure FormCreate(Sender: TObject);
procedure ListView1DblClick(Sender: TObject);
procedure ListView1SelectItem(Sender: TObject; Item: TListItem;
Selected: Boolean);
private
{ Private declarations }
aValue:Integer;
public
{ Public declarations }
end;
var
Form1 : TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
var
i : Integer;
begin
for i := 0 to 50 do
begin
with ListView1.Items.Add do
begin
Caption := 'xyz';
SubItems.AddObject('abc', tobject(i));
end;
end;
end;
procedure TForm1.ListView1DblClick(Sender: TObject);
begin
if avalue>-1 then
showmessage(inttostr(aValue));
end;
procedure TForm1.ListView1SelectItem(Sender: TObject; Item: TListItem;
Selected: Boolean);
begin
if selected then
avalue:=Integer(Item.SubItems.Objects[0]) else
aValue:=-1;
end;
end.
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs,
ComCtrls;
type
TForm1 = class(TForm)
ListView1: TListView;
procedure FormCreate(Sender: TObject);
procedure ListView1DblClick(Sender: TObject);
procedure ListView1SelectItem(Sender: TObject; Item: TListItem;
Selected: Boolean);
private
{ Private declarations }
aValue:Integer;
public
{ Public declarations }
end;
var
Form1 : TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
var
i : Integer;
begin
for i := 0 to 50 do
begin
with ListView1.Items.Add do
begin
Caption := 'xyz';
SubItems.AddObject('abc', tobject(i));
end;
end;
end;
procedure TForm1.ListView1DblClick(Sender: TObject);
begin
if avalue>-1 then
showmessage(inttostr(aValue));
end;
procedure TForm1.ListView1SelectItem(Sender: TObject; Item: TListItem;
Selected: Boolean);
begin
if selected then
avalue:=Integer(Item.SubItems.Objects[0]) else
aValue:=-1;
end;
end.
![]() |
Similar Threads
- how to print in vb.net (VB.NET)
- error creating substring (VB.NET)
- Need help with this game i've created (VB.NET)
- To Search a record in datagridview (VB.NET)
- Mysql Question (PHP)
- Signal Processing: Hadamard Matrices (C)
- Webservice (ASP.NET)
- stored string (C)
- accessing private data members (C++)
Other Threads in the Pascal and Delphi Forum
- Previous Thread: USB to Parallel
- Next Thread: Read of RS232
Views: 727 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for Pascal and Delphi





