Solved

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

Posted on 2003-11-07
6
297 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi: ForceDirectory plain function 7 49
Performance of SQL statement 37 137
Microsoft Access 97 and Delphi XE2 9 71
Firemonkey Queue list 1 27
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

763 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