Solved

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

Posted on 2003-11-07
6
295 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
delphi exception 7 65
Printing problem 2 97
How to create virtual printer while installing my application 5 53
RESTRequest Parameter 4 32
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

825 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