Solved

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

Posted on 2003-11-07
6
287 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

743 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

11 Experts available now in Live!

Get 1:1 Help Now