Hi.
I want to make a string grid to display some kind of vertical cursor to highlight the current selected column. So, in MouseDown I call setCurPos, then I call InvalidateCol to invalidate current column. This calls the DrawCell. DrawCell paints the cursor on current column.
The problem is this: if I have more rows in grid then it can display some of them will not be visible (of course) so grid's vertical scroll bar will automatically appear. When I scroll down to see the rows at the bottom of the grid, the cursor is not painted in these rows. It looks like the number of bottom rows (now visible on screen) in which the cursor is NOT painted is proportional with the number of invisible rows in the top of the grid.
If I minimize and restore the application, the cursor is nicely painted. So, obviously the invalidateColumn() is not working.
procedure TmyGrid.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
VAR aCol, aRow: Integer;
begin
MouseToCell(X, Y, ACol, ARow);
...
inherited MouseDown(Button, Shift, X, Y);
CursorPosFocus:= ACol;
end;
procedure TmyGrid.setCurPos(CONST NewColumn: Integer);
VAR OldPos: Integer;
begin
...
OldPos:= CursorPos;
FCursorPos:= NewColumn;
...
//- This is not working:
//InvalidateCol(OldPos);
//InvalidateCol(NewColumn);
//Update;
//- THIS WORKS:
InvalidateGrid;
end;
procedure TmyGrid.DrawCell(ACol, ARow: integer; ARect: TRect; AState: TGridDrawState);
Var TempRect: TRect;
begin
inherited;
...
{DRAW CURSOR}
if CursorPos= ACol then
begin
TempRect.Top := 0;
TempRect.Left := ARect.Left;
TempRect.Right := ARect.Right;
TempRect.Bottom:= ClientHeight-2;
Frame3D(Canvas, TempRect, $909090, $808080, 1);
end;
end;
Delphi 7, Win XP