Can class constants be extended?

For example ListBox has a ColumnType. Is it possible to add more column types?

If you mean like for instance adding an emoticon column type where according to data you get happy face or sad face, not unlike type checkbox, at first glance, it seems possible by subclassing Listbox. Or do you mean something else ?

That’s what I mean. But how would subclassing do it?

No you cant extend the constants themselves
But with a subclass you could define additional ones & in the subclass check for them OR the ones defined in the super

Yes you can. ColumnType is an Integer, not an enum. Control classes can not have enums, so even the built-in controls have to use constants like Listbox.TypeCheckbox.

You can make a subclass of Listbox, add more Type… constants (for example TypePicture = 99). You then override bot ColumnType methods (the docs say it is a property, but it’s not true). In these methods you have keep track of the additional constants and then it’s up to you to handle everything when a column is set like ColumnType(3) = Listbox.TypePicture.

You see there are several replies already. I would add a ColType computed property, and in the setter simply have it modify the regular ColumnType for regular types, plus add my own TypeEmoticon as a constant. Then it is up to additional methods to manage the actual implementation through, for instance, CellBackgroundPaint to show the emoticons.

Thanks all, will give it a go :wink:

[code]Class MyListbox Inherits Listbox

Const TypePicture = 99

Private Property mColumnType() As Integer

Event CellTextPaint(g As Graphics, row As Integer, column As Integer, x as Integer, y as Integer) As Boolean
If mColumnType(column) = TypePicture Then
Dim pic As Picture = CellTag(row, column)
g.DrawPicture(pic, 0, 0)
Return True
End
End

Sub ColumnType(index As Integer, Assigns value As Integer)
If mColumnType.Ubound < ColumnCount - 1 Then
ReDim mColumnType(ColumnCount - 1)
End
Super.ColumnType(index) = value
If value <> mColumnType(index) Then
mColumnType(index) = value
Invalidate()
End
End[/code]

In the Open event of a MyListbox instance:

[code]Me.HasHeading = True
Me.ColumnCount = 2
Me.ColumnType(1) = MyListbox.TypePicture

Dim pic1 As Picture = New Picture(100, 20)
pic1.Graphics.ForeColor = RGB(0, 255, 255)
pic1.Graphics.DrawString(“Picture 1”, 5, 16)

Dim pic2 As Picture = New Picture(100, 20)
pic2.Graphics.ForeColor = RGB(255, 0, 255)
pic2.Graphics.DrawString(“Picture 2”, 5, 16)

Me.AddRow(“Row 1”, “”)
Me.CellTag(Me.LastIndex, 1) = pic1
Me.AddRow(“Row 2”, “”)
Me.CellTag(Me.LastIndex, 1) = pic2[/code]
One could also override AddRow() to take Variants instead of Strings, so that this would become possible:

Me.AddRow("Row 1", pic1) Me.AddRow("Row 2", pic2)

Thanks Eli!