0
votes

With FireMonkey and several items in a TListBox...

I'd like to be able to allow/cancel an item change...

Like we can do it with the TListView's event: OnChanging

The events OnMouseDown & OnKeyDown are triggered before the change (item values are still for the current/old selected item, not for the new selection)...

So I can stored easill stored the current ListBox ItemIndex... and after the change, move back to it.. but this is just awful, dirty, ...

Anyway to do it nicely?

1

1 Answers

0
votes

Your probably best off creating a custom component to add the functionality by overriding the SetItemIndex method:

type TCustomListBox = class(TListBox)
  protected
    procedure SetItemIndex(Value: Integer);override;
  end;

procedure Register;

...

procedure Register;
begin
  RegisterControls('Custom', [TCustomListBox]);
end;

procedure TCustomListBox.SetItemIndex(Value: Integer); 
begin
  if <condition> then
inherited
end;

initialization
  RegisterFMXClasses([TCustomListBox]);
end;

You can, of course, add an event for the conditional.