ListBox Changed event? How?

Hi all,

I have a ListBox which needs to react to the window being resized. Simple way of dealing with this is of course to call a method in the listbox from the resizing event of the parent window.

However I would like the code to deal with this to be inside the ListBox if possible (so it is completely self-contained).

The CellPaint and CellBackgroundPaint event fire too often to be useful.

I know I could use a timer to achieve this (check periodically to see if the width or height of the parent window has changed), but is there a way to do it without a timer? Or have I exhausted all the possibilities?

TiA

Markus

[quote=163896:@Markus Winter]The CellPaint and CellBackgroundPaint event fire too often to be useful.

I know I could use a timer to achieve this (check periodically to see if the width or height of the parent window has changed), but is there a way to do it without a timer? Or have I exhausted all the possibilities?

[/quote]

Use Cell TextPaint but cache the last size

in CellbackgroundEvent

If me.Width <> LastWidth Or Me.Height <> LastHeight Then LastWidth = me.Width LastHeight = me.Height Raise MyResizedEvent End if

  • Karen

I’m not sure what reactions you want. If it is just to resize when the window resizes just set the locks in the Inspector for the Listbox. Depending on which ones you lock the LlistBox will resize with the window. If you have specified the ColumnWidths to be dynamic, e.g. using % or * in the specification, the columns will also resize as the window is resized. No special code needed for this.

Perhaps we need more info on what you want the listbox to do when resizing.

Thanks Karen. I actually tried that too.

What was the problem with that?

A hybrid solution would be in CellBackgroundPaint, when a resize is detected to THEN start a short single shot timer so the code executes after the Painting is done.

  • KAren

I was looking into adding controls to a ListBox but I want all the code to reside in the ListBox if possible.

Now when the window and therefore the ListBox resize then the control goes out of line with the ListBox - unless I add code to the Window.

However that defeats the purpose of the ListBox being self-contained.

So far the best-looking solution is to do as Karen suggested and then close the control when a resizing of the Window occurs.

see https://forum.xojo.com/19393-desktop-listbox-with-combobox/p1#p162848

You may also want to Close it when the listbox is scrolled, as then the Combobox is over the wrong cell.

To detect scrolls track ScrollPosition too in Karens code.

[quote=164191:@Will Shank]You may also want to Close it when the listbox is scrolled, as then the Combobox is over the wrong cell.

To detect scrolls track ScrollPosition too in Karens code.[/quote]
Good point. Thanks!

What I do in such a case is to have a listbox subclass instance and a combobox instance in the window. The combobox instance is on top of the listbox - the exact position doesn’t matter, but it must show the red borders when moving the combobox (indicating that the listbox is now the parent of the combobox.

To get hold of the combox within the listbox subclass, in the Open event of the listbox subclass I loop over all controls in the window and check for the control’s Parent property and the one with Parent = Self is it. Now all code for the combobox can be put in the Listbox subclass (for reacting to combobox events one needs to use AddHandler).