Hi,
If I have a 3 column listbox, with the following values:
Column 0 is empty.
Column 1 contains 205,55,0 (rgb colour code for a shade of red).
Column 2 contains CD3700 (hex colour code, for the same shade of red).
Is it possible to make the cell of column 0 of each listbox row have the background colour which is displayed in column 1 (or column 2, as they will be the same colour).
I do not know which colour will be stored in column 1 and 2 of each row, so I can’t hard code it - I need to somehow do it dynamically.
Hope my question made sense - I basically want column 0 of each listbox row to be the same colour as in column 1 or 2 of that particular row.
Examples:
If row 1 columns 1 and 2 have the colour code for blue - make column 0 of that row blue.
If row 2 columns 1 and 2 have the colour code for red - make column 0 of that row red.
Thanks Tim, but what I am struggling with is how to make the background colour of column 0, the same as the colour code which is in each corresponding column 1?
Examples:
Row 1: Column 1 has the value 000000 - so make the background colour of column 0 of that row, black.
Row 2: Column 1 has the value FFFFFF - so make the background colour of column 0 of that row, white.
That code seems to work ok. You should move the return true inside the if statement so you don’t kill highlighting, but otherwise it looks correct. Assuming of course, you moved the hex code from column 2 to column 1.
And, if you want to make Norman happy, you can move the first three lines, the two dims and the calculation of v, following the if statement. After all, if you are not processing column 0 then you don’t need the dims and the calculation of v.
CellBackgroundPaint fires for every visible cell, whether they have data in them or not. ListBox.Cell() only works for cells that have data in them - otherwise, you get an OutOfBounds exception.
You need to test for row < me.ListCount before you try to access me.Cell(row, 1)