Recent

Author Topic: TListView OnSelectItem event order  (Read 2511 times)

Chronos

  • Sr. Member
  • ****
  • Posts: 256
    • PascalClassLibrary
TListView OnSelectItem event order
« on: May 09, 2015, 11:39:52 am »
Hi all,
I have TListView instance and I need to handle OnSelectItem event so if item is selected then values need to be loaded to form controls and if item is unselected then values need to be saved back from form controls to item. The problem is that selected and unselected events are coming in wrong order. If item is selected and another item is clicked then first selected event on new item is handled and after that unselected is handled on old item. Which is wrong. First unselected event should be fired up and after that selected to new item. Such order would make sense.

ListView is used as virtual with OwnerData set. Tested on Linux and Gtk2. See attached sample project.

If this is not bug then how it should be handled correctly. I can't verify behavior on Windows and Delphi.

mm7

  • Full Member
  • ***
  • Posts: 231
  • PDP-11 RSX Pascal, Turbo Pascal, Delphi, Lazarus
Re: TListView OnSelectItem event order
« Reply #1 on: May 20, 2015, 04:19:08 am »
May be it is a bug. May be events are generated by widget, that is external to Lazarus. I do not know.

But theoretically only onSelect event is enough. Something like this:
Code: [Select]
procedure TForm1.ShellListView1SelectItem(Sender: TObject;
  Item: TListItem; Selected: Boolean);
begin
  if (Item <> nil) and Selected then
   begin
   if MyControlsChanged and Assigned(MyCurrentItem) then
     SaveMyControls(MyCurrentItem);

   MyCurrentItem:=Item;
   LoadMyControls(Item);
   MyControlsChanged:=false;
  end;
end;
...
procedure TForm1.MyControlChange(Sender: TObject);
begin
  MyControlsChanged:=true;
end;



 



 

TinyPortal © 2005-2018