Get (ID) field from Listview Clicked Item

Posted on 2013-06-02
Last Modified: 2016-10-03
Im useing Delphi XE4. Im using an sqLite database(IOS APP).

I have a listView (lvCustomers) i use a sqlDatsaSet to display all the records from the Customers table. I just drag and drop from the Data Explorer, and use Live Bindings to link to the listview(lvCustomers) from the sqlDatsSet.

I want to click on the customers name in the listview(lvCustomers) and get the ID field from the customers table .

I will use this ID to join to the invoice table in the next listvew to display all invoices that belong to the customer ID that i click on (lvCustomer)

How can I get the field Id (Customers.ID) from the item that is clicked on in the listview(lvCustomers)?

It seems TListViewItem has a Tag property. Is it possible to use this with the live binder or without the live binder to grab the ID field ?
Question by:Grant1842
LVL 26

Assisted Solution

by:Sinisa Vuk
Sinisa Vuk earned 50 total points
ID: 39215416
Tag can be used but if you load dataset on your own.
Try to get id field with plain old:
Positioning on LV will make scroll in dataset thought. Try to join table on dataset level.

Assisted Solution

rotem156 earned 50 total points
ID: 39217039
You're welcome.

Accepted Solution

House_of_Dexter earned 400 total points
ID: 39224531
I don't have I can't help you there...I wouldn't get caught up on the new properties...

You want to figure out how they handle SubItems...You use the SubItem to attach your ID value to it and then grab it on the click event...If you can't figure that out...Then create a StringList that coincides with your ListViewItems...and match Names from each list...and then take the ID value from the StringList...

ie. FList[0] = lvCustomers.Items.Items[0].Detail

As you add the Items to your ListView...add the same values to your
//coded without a I make no guarantees ;)

procedure TForm1.AddRecords(aDataSet: TDataset);
  a_Index: integer;
//check to make sure the Dataset values line up with the TListViewItems..
//this is not a method I like...but if you can't figure out how to add a SubItem...It might be your only way
  while not  aDataSet.Eof do
    AddRecord(aDataSet.FieldByName('Name').AsString,    (aDataSet.FieldByName('Name').AsInteger);

procedure TForm1.AddRecord(aName: string; aId: integer);
  FList.AddObject(aName, pointer(aID));//use this method if you can't figure out how to add subitems...  

function TForm1.GetID(aName: string): integer;
  a_Index: integer;
  Result := 0;
  for a_Index := 0 to FList.Count -1 do
     if aName = FList[a_Index] then
        Result := integer(FList.Objects[a_Index]);

Open in new window


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

Title # Comments Views Activity
loading dll from external path 1 211
Newbie Thread Programming 1 139
Find and Replace Stream with 0s 8 57
FMX and jaudiotracker playing memory stream 29 66
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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 will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

920 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

13 Experts available now in Live!

Get 1:1 Help Now