Forum > Lazarus Extra Components

TstringGrid read cell color [solved]

(1/2) > >>

rnervi:
I've been able to colour a cell backgrund using the related event.
I wonder theres is no way to read a single cell Canvas.Brush.Color (as has been settled in the code).
Is there or not a way to read cell colour ?

wp:
No, the grid in its current implementation does not handle individual cell colors. Nevertheless it is possible to change colors by code in the OnPrepareCanvas or OnDrawCell events - but this is your code, and you are the only one how knows why this and that color has been used here and there.

Xenno:
I don't believe that approach is feasible. Cells aren't independent objects; they are simply rectangles rendered within the grid. Since the Canvas belongs to the grid, we must maintain a reference for each cell to track its state—such as its assigned color—or how we determined its color.

rnervi:
tryied this way:

while scanning all cells (rows/col) I'm looking 1 pixel inside the rect, and reading one pixel I get the "cell background color"


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---var      rett: trect; rett := grd.CellRect(Col, Row);             CellColor := n1.Canvas.Pixels[rett.Left + 1, rett.Top -1]; //n1 is the stringgrid component

In this way I can have the "cell color" based on a single pixel  :)

rnervi:
but only if the TstringGrid is "onScreen"

Navigation

[0] Message Index

[#] Next page

Go to full version