Solved

StringGrids' Col and Row properties are not accurate

Posted on 2002-03-27
10
340 Views
Last Modified: 2010-04-04
Hi everyone,

I am using a StringGrid component (a bit modified to display icons in) in my app. When clicked on a certain cell[Col,Row], a particular Popup menu should open giving choices of actions on the contents of the current cell. In other words, if the cell displays a username in it, open a form with user info, and if the cell displays a folder that that user owns, then open that folder. Trouble is, when I use StringGrid.Row and StringGrid.Col, these two properties seem to report the current row and column very inaccurately. They often miss by one and the next row in error. Does anyone know a fix for that?

Thanks
Vlad
0
Comment
Question by:vladh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 6

Expert Comment

by:Stuart_Johnson
ID: 6901370
Hi Vlad,

If you can give me your email address, I'll send you an example application  (compiled + source) which will should you what you want to know.

If you could include in that email a screen shot of what your application looks like running (the grid), that would help me no end.

Cheers,

Stu
0
 
LVL 6

Expert Comment

by:Stuart_Johnson
ID: 6901379
Vlad,

Email me at gtho1971@hotmail.com instead of posting your address here.  I'll reply to you within the next day (we've about to start a long weekend here).

Stu
0
 
LVL 3

Author Comment

by:vladh
ID: 6901436
Stuart,

I appreciate your offer, but this is a public forum and I would like the answer to my question to be publicly readable. I often scan answers to other peoples questions looking for hints to help with my questions. I would like others to be able to read this thread later and hopefully find the answer to their questions - this is what "Exchange" is all about.

Thanks
Vladimir
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Expert Comment

by:ginsonic
ID: 6901748
I agree with you, Vlad :o)

Regards,
Nick
0
 
LVL 9

Expert Comment

by:ITugay
ID: 6901826
Hi vladh,

>> these two properties seem to report the current
>> row and column very inaccurately.

??? never noticed. Seems the problem in another place. Can you show simplified part of code you using to open popup menu?

------
Igor.
0
 
LVL 6

Expert Comment

by:Stuart_Johnson
ID: 6904878
As I always do, if you accept the answer, the code will be pasted into the forum anyway.

No problems tho.

Stu
0
 
LVL 3

Author Comment

by:vladh
ID: 6908475
Stuart,

The answer to my question is likely no longer than a couple of lines of code. If your app contains it, I would appreciate it if you could paste the relevant parts here.

Basically my StringGrid is a modified component (StringGrid descendant). The changes I made to it allow images to be painted in the cells; it also allows images to be drawn from different imagelists. I suspect there must be some mechanism that keeps track of the current row/column which breaks when I paint the cell contents in the overriden DrawCell method.

Could someone explain the general use of the Notify method and whether or not it would be relevant in my case?
Thanks
Vlad
0
 
LVL 3

Accepted Solution

by:
SteveWaite earned 50 total points
ID: 6911162
maybe this helps you:

  TMyKeyGrid = class(TStringGrid)
  private
    FCol, FRow: Integer;
  // ..
  protected
    function SelectCell(ACol, ARow: Longint): Boolean; override;
  // ..

implementation

function TMyKeyGrid.SelectCell(ACol, ARow: Longint): Boolean;
begin
  FCol := ACol;
  FRow := ARow;
  Result := True;
end;

procedure TMyKeyGrid.MouseDown(Button: TMouseButton; Shift: TShiftState;
  X, Y: Integer);
var
  B: TMouseButton;
begin
  if ((Button = mbRight) and (Pos((IntToStr(FCol) + ':' + IntToStr(FRow)), FOffCells) > 0))
    then B := mbLeft
    else B := Button;
  inherited MouseDown(B, Shift, X, Y);
end;

procedure TMyKeyGrid.DblClick;
begin
  if (Pos((IntToStr(FCol) + ':' + IntToStr(FRow)), FOffCells) = 0)
    then inherited DblClick;
end;

procedure TMyKeyGrid.KeyDown(var Key: Word; Shift: TShiftState);
begin
  if (Key in [vk_Escape, vk_Up, vk_Down, vk_Left, vk_Right]) and (Pos((IntToStr(FCol) + ':' + IntToStr(FRow)), FOffCells) <> 0)
    then inherited KeyDown(Key, Shift)
    else
      if (Pos((IntToStr(FCol) + ':' + IntToStr(FRow)), FOffCells) = 0)
        then inherited KeyDown(Key, Shift);
end;

Regards,
Steve
0
 
LVL 3

Author Comment

by:vladh
ID: 6911291
Thanks to everyone who responded. The problem was in my own buggy code ;( and is now fixed. Steve deserves the points for an actual attempt to get the problem fixed and for some code I could use for a different purpose ;)

Thanks again
Vlad
0
 
LVL 3

Expert Comment

by:SteveWaite
ID: 6911400
glad to help Vlad :)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question