Listbox Subclass Q

API1
I cant work out how to do this…
If I create a class that inherits from Listbox
and add a CellTextPaint event to the class

when I set an on-screen listbox to inherit from my class, I get a message to say that the parent has already implemented the event.
How can I resolve that, when I may want the on-screen listbox to do additional things?

Add an Event Definition to your class for CellTextPaint and remember to RaiseEvent CellTextPaint in your Subclasses CellTextPaint Event (bubble the event) so that code runs that you place into the instanced event on the window.

2 Likes
  • first create a subclass from listbox ( eg. ccListbox )

  • add an EventDefinition to ccListbox ( eg. ueCellTextPaint )

  • in CellTextPaint call ueCellTextPaint at the end of the script !!!

  • inherit a new listbox from ccListbox ( eg. [name]Listbox )

  • now you can select the ueCellTextPaint event in your inherited listbox like any other event

  • you can now have code which runs in ccListbox only, only in inherited listbox or in both list boxes

hope it makes sense

I have tonnes of those events … works perfect !!!

This sounds like a good start, but where does the CODE go?
In an event definition, you cannot enter code,
I cannot rename an event handler in the class.

I guess Jeff has me muted/blocked? Can someone tell him to check out File>New Project>Examples>Desktop>Custom Controls>LinkLabel

No need to have another name if you intend to substitute the CellTextPaint event adding some internal preprocessing. You just need RaiseEvent CellTextPaint at the end instead of calling it.

So it would become

  • add the CellTextPaint EventDefinition to your Listbox subclass. It does nothing here, it just defines a fireable event. No code involved.
  • Add your handler code for CellTextPaint and RaiseEvent CellTextPaint in that code so it fires the event (that you defined in the step above) to the user of this subclass.
1 Like

Sorry all. (I don’t have Julian blocked, but…)
Im feeling stupid at the moment, as I don’t quite understand this.

The listbox and class CellTextPaint events clashed in the compile stage if the subclass and actual listbox both had one.
I dont see how this code will resolve that yet.

The stuff the event does needs to return a boolean, doesn’t it?

In the class:
I add an event definition called CellTextPaint , and it has all the usual parameters.
It doesn’t have any code.
I add an event handler. It has all the usual parameters, and it does return a boolean.

IF I add raiseEvent CellTextPaint in that event handler, does that mean I am making the actual listbox execute any code that it contains?

How do I tell the actual listbox that the class did something which requires the return has to be true - there is no boolean parameter?

(Im experimenting now,btw, and may stumble on these answers myself)

Methods are top-down. Event definitions are bottom-up.

If you are in an event like the paint event in a subclass you don’t want to know the parent class being dependent on the subclass. The subclass does the paint, during the paint it tells the parent class to do it’s thing by raising the paint event to the parent and then the subclass finishes the paint.

The code in the subclass looks like:

'some code here
RaiseEvent Paint
'some other code here

That way each class can do what it has to do.

If you want your raised event to return something then declare a return type and use the result:

dim myValue as String = RaiseEvent myevent

where myEvent returns a string.

like this: ?

return true or raiseevent CelltextPaint ( g,row,column,x,y)

Sure you can do that.

Sadly, didn’t propagate to the actual listbox… the actual listbox CellTextPaint doesnt fire when I raiseEvent

I’m
reaching the ‘never mind, just do it in all 3 listboxes instead of creating a class’ stage, as I know that works

:slight_smile:

You need to reimplement the event in the parent class. And no please don’t give up. Understanding how to raise events is very important.

1 Like

What does that mean though?

I have a class based on listbox

It has an eventdefinition called CellTextPaint
It has an event handler called CellTextPaint, with

//some code
return true or raiseevent CelltextPaint ( g,row,column,x,y)

and has had otheer variations of similar

I have a listbox on a window
I set it to inherit from my class.

It has an event handler called CellTextPaint, containing some code
…which doesnt fire, even though the class’s code did run.

Return true or x will never run x because true is always true

Just

Return RaiseEvent CelltextPaint ( g,row,column,x,y)

mmm…?

I thought I was returning true or (result of the raiseevent)
How do I get the result of the event raised if not this way?

1 Like

Hey, Something is weird here…

If I put this in the event:

Function CellTextPaint(g As Graphics, row As Integer, column As Integer, x as Integer, y as Integer) Handles CellTextPaint as Boolean
  
  // Do some magic here
  System.DebugLog "fired "+row.ToString+" , "+column.ToString
  
  Return RaiseEvent CellTextPaint(g, row, column, x, y)
  
End Function

With my subclassed lisbox with 5 x 3 cells. It just fires once.

Need to rest a bit now. But for me, right now, seems a bug.

I can’t check atm, on mobile, did you scroll up the message pane?

btw, just in case anyone is interested, all this work is only because in older Xojo versions on Windows, when I set the color scheme to be high contrast black, checkboxes in a list box cannot be seen. (black on black)

I’ve spent months making my own dark mode stuff, and this is the last thing: a checkbox replacement.
(For reasons, I can’t use anything after Xojo 2018 on Windows in this project due to the changes made in the graphics engines , so Xojo2021R3 doesn’t solve that for me.)

By the way, I’m using a containerControl with a listbox,
wherever I use a listbox, I add that containerControl (ccListbox)

Here I can select the userEvent ue+name where you can put in the code

I’m clearly past it.
Thanks for the picture, but I cannot follow what that is doing. :slight_smile: