?
Solved

StringGrids' Col and Row properties are not accurate

Posted on 2002-03-27
10
Medium Priority
?
341 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
Technology Partners: 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 150 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses
Course of the Month13 days, 23 hours left to enroll

800 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