?
Solved

Get (ID) field from Listview Clicked Item

Posted on 2013-06-02
3
Medium Priority
?
2,692 Views
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 ?
0
Comment
Question by:Grant1842
[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
3 Comments
 
LVL 28

Assisted Solution

by:Sinisa Vuk
Sinisa Vuk earned 200 total points
ID: 39215416
Tag can be used but if you load dataset on your own.
Try to get id field with plain old:
  sqlDatsaSet.FiledByName('IDField').AsInteger
Positioning on LV will make scroll in dataset thought. Try to join table on dataset level.
0
 
LVL 4

Assisted Solution

by:rotem156
rotem156 earned 200 total points
ID: 39217039
You're welcome.
0
 
LVL 6

Accepted Solution

by:
House_of_Dexter earned 1600 total points
ID: 39224531
I don't have XE4...so 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 FList...like
//coded without a compiler...so I make no guarantees ;)


procedure TForm1.AddRecords(aDataSet: TDataset);
var
  a_Index: integer;
begin
//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
  aDataSet.First;
  while not  aDataSet.Eof do
  begin
    AddRecord(aDataSet.FieldByName('Name').AsString,    (aDataSet.FieldByName('Name').AsInteger);
     aDataSet.Next;
  end;
end;

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

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

Open in new window

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

649 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