TListBox OnMeasureItem called only once - GTK lazarus / 31-LCL ---------------------------------------------------------------------- spassigl · 2020-12-30 18:33 I have a Listbox set to lbOwnerDrawVariable and if I set the item height to 0 the item is still drawn. I'm just trying to set the item height to 0 instead of removing the item and then adding it back. I just want to toggle its visibility. This is the code that toggle an item visibilty with a button click Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i        begin        obj := MyListBox.Items.Objects[MyListBox.ItemIndex];      if obj.ClassNameIs('TMyObject') then        begin               with obj as TMyObject do Visible := not Visible;          end;        WorkoutListBox.Invalidate;    end;  This is the OnMeasureItem event handler Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TMyForm.TMyListBoxMeasureItem(Control: TWinControl;    Index: Integer; var AHeight: Integer);var   obj: TObject;begin   obj := MyListBox.Items.Objects[Index];   if obj.ClassNameIs('TMyObject') and (not (obj as TMyObject).Visible) then      AHeight := 0;   WriteLn('Measuring Item ' + MyListBox.Items[Index] + ': ' + IntToStr(AHeight));end; The OnMeasureItem event is called only once, when the component is created, but not called again after Invalidate. I have tried Refresh, Repaint and Update as well to no avail. Do you think I have found a bug? Thanks ---------------------------------------------------------------------- jamie · 2020-12-31 02:39 That's the way it works in windows and most of if not are all mimic of them. The OnMeasureItem Event only takes place once when the List box is built or items changed. When ever you add, delete etc an item in the list the events should get called again because it has to rebuild the list. so if you don't want the item visible then remove it and put back later.  If you want to keep track of whats there and whats not have a Stringlist with all the items in it but also set the OBJECT member for each item the matching index that reflects position in the list or, in the list for the TlistBox use the object member of each to store the index to the main stringlist  I think you get what I mean.. Use the ListBox for your viewing of only the strings you need from the background stringlist that holds all of them. ---------------------------------------------------------------------- spassigl · 2020-12-31 08:28 Yes that's what I ended up doing - adding and removing items. During my tests I also noticed that if I change the item string to empty ('') the OnMeasureItem is indeed called but even if I set the item height to 0 or any value smaller than the default height, the item still gets the default height. I set ItemHeight to 20, and 0 too. If I make it bigger then it works. Is there a minimum size for the items? ---------------------------------------------------------------------- jamie · 2020-12-31 12:26 I would need to check the Windows implementation on that one, I think you can make it smaller but I could be wrong there... Seems I remember doing this before and you could be correct on this assertion, the min size could be the font height.. EDIT:  And to add to that!    "I am never wrong, once I thought I was but I was mistaken!"