TListView Color...

Hi all

i have a list view with 2 columns, "Color" and "Name"...

I want to put one color for each row in the Color column. For a start, I have tried adding this in the onOwnerDraw:

  ListView.Canvas.Brush.Color := clGreen;
  ListView.Canvas.FillRect (Rect(0,0,2,2));

I thought this will fill a little box at the top left hand corner, but it
filled up the entire row. How do I solve this?


Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

kambizConnect With a Mentor Commented:
After filling the rectangle, change the brush color to previous color of it.

I hope this helps you
If I drop a listview on a form and add a button where I put the two of your code lines, it does fill only a little box at the left top corner.

Try a testproject with just a listview and your code, because it's correct.

keithcslAuthor Commented:
hei guys

i found the problem. first, i did not change the color back. but then, found that after coloring the canvas, the add item routine recolors it back to white.

it's getting too complicated. i have decided to abandon this method.

however, kambiz gave the right solution, so i am accepting that.

PS: i am posting another similar question.

All Courses

From novice to tech pro — start learning today.