TListview FMX onclick event along with Toggle Design

Viewed 1252

Toggle Design mode in FMX Listview give you this

The implementation is the following:

ds.first;
  while not(ds.Eof) do
    begin
      L := LV1.Items.Add;
      L.Data['Part_No']   := ds.FieldByName('Part_no').AsString;
      L.Data['Part_Name'] := ds.FieldByName('Part_name').AsString;
      L.Data['LocNo']     := ds.FieldByName('Loc_No').AsString;
      L.Data['Qty']       := ds.FieldByName('BAL').AsFloat;
      ds.Next;
    end;

I add items dynamically using code

How can OnItemClick event fire to detect which element has been clicked. Very frustrating to find out just simple thing.

Any help appreciated.

3 Answers

"How can detect which element has been clicked or selected? Very frustrating to find out just simple thing."

1.- select structure like.: TlistView1/ItemAppearance/Item

2.- in object Inspector, change Appearance to DynamicAppearance.

3.- in object Inspector, add a new TTextObjectAppearance, change name to "MUV_HELY" or something.

4.- Add item

ListView1.Items.Add.Objects.FindObjectT<TListItemText>('MUV_HELY').Text:= //Your record value, or something. /*string all the time*/

/// With image ///

> ListView1.Items.Add.Objects.FindObjectT<TListItemImage>('IMAGE01').Bitmap := FMX.Graphics.TBitmap.CreateFromFile('.\Jelleg\List\'+Format('%.4d',[AdatSor.GYARTASISZAM])+'.bmp');

'.\' -> means your application Release folder. where your *.exe is. 'Format('%.4d',[AdatSor.GYARTASISZAM])' -> means for these example, in my database stored file name, what i have to call from file. My database value 1 and 2, but in file name I need to call 0001.bmp and 0002.bmp.

5.-Read back item

procedure TMainMenu.ListView1Change(Sender: TObject);
begin
  if ListView1.Selected<>nil then ShowMessage(TAppearanceListViewItem(ListView1.Selected).Objects.FindObjectT<TListItemText>('MUV_HELY').Text);
end;

If you change the selected item with keyboard (up, down, left, right), then you will get back the selected value, without clicking on it.

Use the OnItemClickEx event instead. This passes the ItemObject clicked, which you can then check the ItemObject.Name to see which element was clicked.

Related