Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1037343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:50:29+00:00 2026-05-16T14:50:29+00:00

I want to make a string grid to display some kind of vertical cursor

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T14:50:30+00:00Added an answer on May 16, 2026 at 2:50 pm

    You are doing nothing wrong, you just got caught by a bug in the VCL grid implementation that has been in the Delphi 4 VCL (I don’t have any earlier CD here to check, but it might even have been in the 16 bit Delphi VCL already) and is still with us in Delphi 2009.

    Both methods to invalidate a whole row or column do this by calculating an area of cells that is passed to the internal InvalidateRect() method. This area always starts with the column / row 0, and extends to the first completely invisible row / column. It’s quite obvious that this will only ever work correctly for an unscrolled client area. What the code should do instead is invalidate to the last column / row, and let the code in the InvalidateRect() helper figure out which cells are indeed visible and calculate the client area that needs to be invalidated from that.

    Since you are writing your own class you could easily implement your own methods to invalidate the correct range of cells; I did the same many years ago, together with more methods to invalidate multiple columns, multiple rows and whole blocks of cells. Since InvalidateRect() is private (great thinking there too) you need to use the Windows API function with the same name, and calculate the rectangle to be invalidated using either the CellRect() or BoxRect() method.

    While InvalidateGrid() does work for you it is really kind of a sledge hammer – it invalidates the whole grid, which I think is not what you wanted when you started using InvalidateCol().

    For your experiments you should make paint cycles for each cell easily visible. Causing the background colour of the cells to change with each update is a simple way to check that you really only do minimum screen redraws. Something like

    StringGrid1.Canvas.Brush.Color := RGB(Random(256), Random(256), Random(256));
    StringGrid1.Canvas.FillRect(Rect);
    

    in the OnDrawCell event handler works fine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to make a program that will read some number in string format
I want to make timer string with CCLabelAtlas. The problem is the character, :.
I want to make a reverse string function and I have done it like
I want to make sure a string has only characters in this range [a-z]
What is needed to make String.IsNullOrEmpty() count whitespace strings as empty? Eg. I want
i want to make typewriter effect like: http://img139.imageshack.us/img139/9775/screenshot0002mm2.gif dim s as string = 123
I have a string String origStr = /unwanted/wanted1/wanted2/and_so_on i want to make this as
I have this json string: $row['medium'] = {\medium\:13|17|1|14, \medium_sub\:21}; now I want to make
original string is a,d,k I want to remove all , and make it to
I am trying make a clock. The hour is a string. I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.