Solved

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

Posted on 2003-11-07
6
301 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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

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 video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

707 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