Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to highligh multiple rows in a StringGrid

Status
Not open for further replies.

asja

Technical User
Nov 6, 2008
3
BA
Hi all,

I need to enable the user to click in any cell of the first left column (Column 0) of a StringGrid (with no fixed columns) result being that the whole row in which that cell is is highlighted/be colored - whichever would allow the changed color to stay with that row when it will be later sorted in a separate function.

This should allow highlighting not only adjacent but also nonadjacent rows.

Also, after clicking again at the highlighted row, the highlight should disappear.

I changed the property goRowSelect to true but clicking the cells highlights only single row and immediately clears the highlight when some other cell is clicked... Also, Shift here works, but Ctrl (selecting nonadjacent rows does not...)

Can anyone help me with this?

Also, what is the way to detect highlighted/colored rows from inside a function?

thanks,
 
Hi,
I red this and some other material but I still can not make it..

What I made by now is this; on a form I have:

1. a StringGrid called gridMain within a form called frmIndexSize

2. an event called TfrmIndexSize::gridMainDrawCell

3. another event called TfrmIndexSize::gridMainMouseDown

4. and a variable visible to all functions on the form - aCol - in order to pass it to gridMainDrawCell function to be used for ACol value...

...and I am sure that this is very clumsy way, but I do not know better.

The whole thing looks something like this:

void __fastcall TfrmIndexSize::gridMainDrawCell(TObject *Sender, int ACol,
int ARow, TRect &Rect, TGridDrawState State)
{
if(( ACol >= 0) && (ARow >= 1 )) // get rid of focus
{
gridMain->Canvas->Brush->Color=gridMain->Color;
gridMain->Canvas->FillRect(Rect);
gridMain->Canvas->Font->Color= gridMain->Font->Color;
gridMain->Canvas->TextOut(Rect.Left, Rect.Top, gridMain->Cells[ACol][ARow]);
}

if (ARow==aRow )//this one is suposed to color the wole row...
for (int a=0;a<=gridMain->ColCount-1;a++)
if (ACol==a)
{
gridMain->Canvas->Brush->Color = clPurple;
gridMain->Canvas->Font->Color = clBlack;
gridMain->Canvas->FillRect(Rect);
}

// draw the text
gridMain->Canvas->TextRect(Rect, Rect.Left, Rect.Top, gridMain->Cells[ACol][ARow]);
}
//--------------------------------------------------------
void __fastcall TfrmIndexSize::gridMainMouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
int x, y;
gridMain->MouseToCell(X, Y, x, y);

if (x==0 && y>0)
aRow=y;
}
//---------------------------------------------------------------------------

When I click in the cells of the leftmost column only some cells get colored, and sometimes de-colored..

I know that I made a mess out of this so please give me some hints about what else I could try.

thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top