Format Cells Upon Inserting or During CellTextPaint

I have a few date columns in my listbox. I store the SQLDateTime in the CellTag. If the date is yesterday, today or tomorrow, I write that in the cell, instead of the actual date.

My question is, is it better to do this in my listbox populate method, or in the CellTextPaint event? There will also be other types of formatting for the other columns.

Suppose one day you want to be able to let people display dates with relative dates (today , yesterday, tomorrow as well as the actual date for other dates) OR always display the actual date

The only way to do that would be to have the actual data in a cell tag and the in cell paint draw the format the user wants

Norman, I think I’m missing your point. In all cases the actual raw data is kept in the cell tag. However, formatting that data for the cell text can be done upon inserting into the listbox or in the CellTextPaint event, right?. I was wondering which is the best approach. Thanks

I would not change the text to be displayed in the cell text paint event

I store all values in the CellTag and print the formatted result in the Cell. This is done in the listbox load.

This then enables me to allow editing of a cell and use the CellTag value for the display to the user. This is particularly useful if you are storing number values. I do a lot of financial software and my formatting is:

myListbox.Cell(myListbox.LastIndex, theRow) = Format(myNumberValue, "#,###,###,##0.00\\ ;(#,###,###,##0.00);\\ ") MyListbox.CellTag(myListbox.LastIndex, theRow) = myNumberValue
In the CellClick event I use:

Cell(row, column) = Str(CellTag(row, column), "-#.########") CellType(row, column) = Listbox.TypeEditableTextField EditCell(row, column) Return True
Lastly, in the CellAction event I use:

CellTag(row, column) = Val(Trim(Cell(row, column))) Cell(row, column) = Format(CellTag(row, column), CurrencyFormat)
This gives you the best of both worlds.

The above code does not check the column that you are using, that is up to you as you will know which columns to use.