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 MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

StringGrid Repaint,Refresh ?

Status
Not open for further replies.

Tilen

Programmer
Apr 2, 2005
75
SI
Hi

I have a stringgrid with names. And when I select a row, I color it with green, so it obvious which one is selected.

What I did now is to color rows when I just hover over the grid with mouse (OnMouseMove)... so if I move mouse up and down, rows are coloring green and back to original color, so the coloring follows the mouse movement. It's like I would move up and down with keyboard and current row is colored.

This works, but is not useful because I use Grid.Refresh or Grid.Repaint and it kind of flashes the whole grid while repaint/refresh.

So, it works, but the flashes are annoying.

Does anybody know how to make it a bit faster? Or maybe how to refresh/repaint just specific row? That way I could paint previous row with original color and current row with green, and not whole grid needs to be refreshed.

Thanx
Tilen
 
You could try using LockWindowUpdate() on it.
It stops windows from updating forms or whatever
handle you pass to it. To unlock it again just simple
do LockWindowUpdate(0);

[bobafett] BobbaFet [bobafett]
Code:
if not Programming = 'Severe Migraine' then
                       ShowMessage('Eureka!');
 
Forgot to post: so these two have to surround your draw
code.

[bobafett] BobbaFet [bobafett]
Code:
if not Programming = 'Severe Migraine' then
                       ShowMessage('Eureka!');
 
I'll try and let you know how it goes.

thanx.
 
Surely if you use LockWindowUpdate then you won't see the changes in colour as you move the mouse over the grid?
How are you changing the colours in the grid as you move the mouse? I used the following and got no flashing at all

Code:
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
begin
  if (gdFixed in State) then
  begin
     StringGrid1.Canvas.Brush.Color := StringGrid1.FixedColor;
     StringGrid1.Canvas.FillRect(Rect);
     StringGrid1.Canvas.TextOut(Rect.Left, Rect.Top, StringGrid1.Cells[ACol, ARow]);
  end
  else if (ARow = FHoverRow) then
  begin
     StringGrid1.Canvas.Brush.Color := clGreen;
     StringGrid1.Canvas.FillRect(Rect);
     StringGrid1.Canvas.TextOut(Rect.Left, Rect.Top, StringGrid1.Cells[ACol, ARow]);
  end
  else
  begin
     StringGrid1.Canvas.Brush.Color := StringGrid1.Color;
     StringGrid1.Canvas.FillRect(Rect);
     StringGrid1.Canvas.TextOut(Rect.Left, Rect.Top, StringGrid1.Cells[ACol, ARow]);
  end;
end;

procedure TForm1.StringGrid1MouseMove(Sender: TObject; Shift: TShiftState;
  X, Y: Integer);
var
  col, row: integer;
begin
  StringGrid1.MouseToCell(X, Y, col, row);
  FHoverRow := row;
  StringGrid1.Refresh;
end;

n.b. FHoverRow is an integer field belonging to TForm1

Steve
 
I guess I had a bit more complicated drawing procedure and it took a bit longer to run, so flashing appeared.

With this one, it doesn't.

Thanx a lot.

Tilen
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top