Solved

StringGrids' Col and Row properties are not accurate

Posted on 2002-03-27
10
332 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
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 6

Expert Comment

by:Stuart_Johnson
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 9

Expert Comment

by:ginsonic
Comment Utility
I agree with you, Vlad :o)

Regards,
Nick
0
 
LVL 9

Expert Comment

by:ITugay
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 6

Expert Comment

by:Stuart_Johnson
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
glad to help Vlad :)
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now