Solved

StringGrids' Col and Row properties are not accurate

Posted on 2002-03-27
10
336 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
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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

808 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