Listbox cell showing what looks like an apostrophe

I am getting what looks like an apostrophe in the cells of a listbox. It doesn’t happen all the time and it seems to depend on the data in the listbox. It will happen everytime with the same data set. It’s probably an artifact from the content of the header row or the list box rows. Changing the size of the listbox rows does not correct this. I can’t figure out how to increase the size of the header row. Suggestions?

It’s the cell background paint code that’s doing it. This is some old code.

[code] //fill in even numbered rows
//with light blue color
//odd rows get no color (i.e. white)
if (row mod 2)=0 then
g.foreColor = rgb(232,235,255)
g.fillrect 0,0,g.Width,g.height
end if

//if selected,
//fill in row with dark blue color and white text
//otherwise draw with black text
if me.selected(row) then
g.foreColor = rgb(66,82,255)
g.fillrect 0,0,g.Width,g.height
g.foreColor = rgb(255,255,255)
else
g.foreColor = rgb(0,0,0)
end if

//draw the text
g.drawstring me.cell(me.lastIndex,1),0,0 //out of bounds exception
exception err
if err IsA OutOfboundsException then //when row is deleted
//do nothing, row has been deleted
end if[/code]
If I comment out the last section under “draw the text” then it all works fine. I think I need some new cell background paint code.

Better, move that code to the CellTextPaint event and remember to return True.

As Kem mentioned, move all text drawing to CellTextPaint.
Return True in both events or the Xojo framework will do the standard drawing in front of your drawing.
The line

g.drawstring me.cell(me.lastIndex,1),0,0 //out of bounds exception

… doesn’t make much sense to me. LastIndex is the index of the last row inserted or added. Use the parameters row and column to get the cell value (and there is no need to check for OutOfboundsException if you use these two parameters). So your CellTextPaint event would be:

if me.selected(row) then g.foreColor = rgb(255,255,255) else g.foreColor = rgb(0,0,0) end if g.drawstring me.cell(row, column), x, y) Return True
… where x and y are also parameters of the CellTextPaint event, indicating the position the Xojo framework would draw the text itself, which is usually the correct position.

Yes, sorry, it is in the CellTextPaint event. This is some very old code. I must have picked it up out of some old work.

Eli, your code returns a syntax error on this line:

g.drawstring me.cell(row, column), x, y)

I’m passing the correct parameters into the event.

If I add Return True to my existing code I get a blank window because it’s painting over the data. I know because if I can see a record count and I can see how many rows are painted and there’s a match. If all I run is this code:

if (row mod 2)=0 then g.foreColor = rgb(232,235,255) g.fillrect 0,0,g.Width,g.height end if
It paints over the data in alternating rows. If I add the Return True then a blank window. If I add this code then it works as it should:

if me.selected(row) then g.foreColor = rgb(66,82,255) g.fillrect 0,0,g.Width,g.height g.foreColor = rgb(255,255,255) else g.foreColor = rgb(0,0,0) end if
Again, Return True causes it to paint over the entire listbox showing nothing. It works fine with the two above code blocks and no “Return True”.

Don’t know what to make of that but my gut tells me to leave well enough alone.

I’m unclear. Are you using both events, CellBackgroundPaint for the background and CellTextPaint for the text? Because that’s how you should be doing it.

And that code returns a syntax error because of the extra close paren at the end.

[quote=83630:@Duane Mitchell]Eli, your code returns a syntax error on this line:
g.drawstring me.cell(row, column), x, y)[/quote]
There is a ) too much at the end

An extra ) will do it. Couldn’t see it, too simple. Thanks.

I am only using CellTextPaint, all the code is in that. There probably wasn’t a CellBackgroundPaint back then. I can see what your saying though. The docs show it. I’ll look into that but for now this is working. A good observation, btw.

So all my code is in the CellTextPaint event and it looks like this and works fine.

[code] if (row mod 2)=0 then
g.foreColor = rgb(232,235,255)
g.fillrect 0,0,g.Width,g.height
end if

if me.selected(row) then
g.foreColor = rgb(66,82,255)
g.fillrect 0,0,g.Width,g.height
g.foreColor = rgb(255,255,255)
else
g.foreColor = rgb(0,0,0)
end if
g.drawstring me.cell(row, column), x, y
Return True[/code]

With the code all in the CeltTextPaint event I do believe that upon close inspection you will find that the portion that is painting the background color is not truly filling the entire cell. This has been discussed in a couple of other recent postings. You should really split the code. The part that is filling the cell with color should be in the CellBackgroundPaint and the portion drawing the text should be in the CellTextPaint. Doing that the background color will fully fill the cell and the text will appear positioned as it should. The rectangle used for drawing the text is slightly smaller than the rectangle of the cell to properly space the text from the edges of the cell.

Yes, I’ve noticed that there is somekind of margin or inset that does not get painted. Thanks for the clarification. I will move this as you suggest.