Solved

Move to the table record corresponding to the ListView Item index?

Posted on 2003-11-07
6
291 Views
Last Modified: 2010-04-05
I Iterate through a TTable and create a TListItem (large Icon) in a TListView for each record.
(where TListView viewstyle - vsIcon)

When selecting a ListItem (Icon) in my TListView, I need to set my TTable Cursor position to the record number corresponding to my ListItem (Icon) Index.

Any ideas on how to do this. It would be nice to just be able to set TTable.RecNo to the corresponding index, but the RecNo property doesn't allow for this

Any ideas how to move to the table record corresponding to the ListView Item index?

I could add each of the tables record information as  an object to the Item, and use this information to perform a locate on the Table - any ideas how to add an entire table record as an objectr to the indivisual ListItems?

Shane
0
Comment
Question by:shaneholmes
6 Comments
 
LVL 2

Accepted Solution

by:
Ray_Adams earned 125 total points
ID: 9700586
What kind of database you use?

The best way is use unique filed in table (like autoincrement) . When you add record to ListView you also can add ID (unique field) as Data. After then just locate('id',selectedid,[]);
0
 
LVL 11

Author Comment

by:shaneholmes
ID: 9700775
Um, id like to see if there is another way before I decide to restructure my tables to incorporate autoincrement fields

Jack
0
 
LVL 2

Expert Comment

by:Ray_Adams
ID: 9700892
i think the only way is store some unique information about record, to find it in future when you select item in ListView. I see no other way in your situation without reconstructing database.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 17

Expert Comment

by:geobul
ID: 9700950
Hi,

You are filling your ListView starting from the first record, right? Try this:

procedure TForm1.ListView1Click(Sender: TObject);
var i: integer;
begin
     if ListView1.Selected <> nil then begin
        Table1.First;
        for i := 0 to ListView1.Selected.Index - 1 do Table1.Next;
     end;
end;

Regards, Geo
0
 
LVL 2

Expert Comment

by:Ray_Adams
ID: 9701041
You can use bookmarks in your situation.

this is how to fill listview

     Query1.First;
     while not Query1.Eof do
     begin
          with ListView1.Items.Add do
          begin
               Caption:=Query1FirstName.Value; //just for example
               data:=Query1.GetBookmark;
          end;
          Query1.Next;
     end;

and in OnChange event of listview use this

     if ListView1.Selected<>nil then
     Query1.GotoBookmark(ListView1.Selected.Data);
----------

No extra coding :) ;)
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 9701279
if it a single-user app and the items are not sorted,
then u could also use something like this

dataset.first;
dataset.moveby(ListView1.Selected.Index); //maybe an offset +/- 1 is needed

but i would prefer to store some unique-info into the data-pointer,
rather than a tbookmark (causes that the whole record is cached in memory)

meikl ;-)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now