Change ListBox Background color

I need to change the backcolor of a listobx. With CellBackroundPaint I can paint the cells, but for paint where I don’t have the cells? If I have only one rows and I need to color all listbox?

Use a Canvas with a background color ?

Far better answer:

If row Mod 2=0 then g.foreColor= &cD2EDF5 else g.foreColor= &cD2EDF5 end if g.FillRect 0,0,g.width,g.height

Notice that the color is the same !!!

Works fine even with no Row in the Listbox (more or less).

[quote=287063:@Emile Schwarz]Far Far better answer:

g.foreColor= &cD2EDF5 g.FillRect 0,0,g.width,g.height

?

Do nothing, was my first bet (tested) before Canvas (not tested).

No.
In CellBackroundPaint g.widht and g.height are the size of cell.
I have to color the background of the whole listbox.
If I use the CellBackroundPaint and have only one row this event paint only one row and not all listbox.

…and I have to use libox box bcs need to write some rows.

The only way to color places where there are no rows yet is to use a canvas or a rectangle on top of the Listbox empty area.

CellBackroundPaint
//// color for the whole listbox
g.foreColor= &cD2EDF5
g.FillRect 0,0,g.width,g.height

//// color for the rows
if row < me.ListCount then
g.foreColor= &cE1E1E100
g.FillRect 0,0,g.width,g.height
end if

That used to be the case but was changed quite a while back. Uses complained about the ugly white space below the rows.

maybe

g.ClearRect 0,0,g.width,g.height

on the begin of CellBackroundPaint can remove the ugly white space below the rows

1 Like

@Axel Schneider
In CellBackroundPaint g.width and g.height are the size of the current pain cell. Not listbox.

You are right.

A Listbox with only one row fires all non existing rows up to filling the entirety of height.

This is new to me.

[quote=287095:@Gabriele Marchionni]@Axel Schneider
In CellBackroundPaint g.width and g.height are the size of the current pain cell. Not listbox.[/quote]

You don’t get it. There is NO general Paint for a listbox. ONLY CellBackgroundPaint. If you want to display a single image over the background, for instance, you will have to use the SourceX and SourceY options of Drawpicture to affect each cell the appropriate portion of the image.

[quote=287095:@Gabriele Marchionni]@Axel Schneider
In CellBackroundPaint g.width and g.height are the size of the current pain cell. Not listbox.[/quote]

if there is no cell it paints the background

[quote=287097:@Michel Bujardet]You are right.

A Listbox with only one row fires all non existing rows up to filling the entirety of height.

This is new to me.[/quote]

Well, you fix so many of my misconceptions. Nice to return the favour for once. :wink:

[quote=287109:@Gabriele Marchionni]I don’t know why but to me with CellBackgroundPaint can only draw within the cell (or row).
I wrote this in CellBackgroundPaint:

  g.ForeColor = &cFF000000
  g.FillRect 0,0,g.width,g.height
  g.ForeColor = &c00000000
  g.DrawString "Row", 10, 10

[/quote]
I don’t understand your concept,
how many rows you have created and where?
why you use drawstring and not

lb.cell(rownumber,columnnumber) = "row"

(Textcolor in CellTextPaint)

ok, solved.
@Axel Schneider you’re right.
@Markus Winter yes row fires all non existing.
I’m reading each cell and paint different for each cell value.
My error was:

  if row > me.ListCount  -1 then 
    Return true
  end if

Thank you to all.

For the record:

the answer I gave was tested (without adding rows) and set the whole Listbox with a color. No need to ass a Canvas (as my first answer). The provided code really changed the Lixtbox background color.

So why all the burden ?
Was I wrong ? If so, how ?

Also: giving answers (that proved to be wrong) without testing it first is - for me - a strange concept of giving help.