How to get column and width coordinates of mouse on mouseclick

Let me first introduce what the object is:
I want to create a dataset, which consists of datapoints set using the mouse(with a click), with the points- in between the points set in this way -interpolated. The last thing I think I can do, my problem is with using the mouseclick, so:

I have a TStringDrawGrid object.
Now, what I want to do is get the column and width coordinates(in the TStringDrawGrid object)  of the location at which is clicked with the mouse.
I have been looking around to find some information but I can't get it to work. What I found:


type
  TForm1 = class(TForm)
    DrawDataForm: TDrawGrid;
    BitBtn1: TBitBtn;
    procedure BitBtn1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;


procedure TForm1.BitBtn1Click(Sender: TObject);
var
  X, Y : integer;
  Column, Row: Longint;

begin

  Form1.DrawDataForm.MouseToCell(X, Y, Column, Row);
  showmessage('Col ' + IntToStr(Column) +
    ',Row ' + IntToStr(Row));

end;

But this just returns -1, -1 all the time.

Furthermore, I was only able to set an event to a button(in the delphi editor->DrawDataForm->events), not to any procedure I created myself. How can I do this?

Help MUCH appreciated :)

reynaerdeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Imthiyaz_phCommented:
hai reynaerde

just place the above code into OnMouseUp event of the grid, then u will get the exact row and column index where the mouse was clicked.

to get the width of the column, use ColWidths property:

property ColWidths[Index: Longint]: Integer
0
kretzschmarCommented:
?? usual in your sample x,y are not initialized and the values are randomly

should be more like


procedure TForm1.BitBtn1Click(Sender: TObject);
var
  p : TPoint;
  Column, Row: Longint;

begin
  GetCursorPos(p);  //or was it p := GetCurosrPos;
  p := Form1.DrawDataForm.screentoClient(p);
  Form1.DrawDataForm.MouseToCell(p.X, p.Y, Column, Row);
  showmessage('Col ' + IntToStr(Column) +
    ',Row ' + IntToStr(Row));

end;

just from head

about your other question you should explain more

meikl ;-)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
reynaerdeAuthor Commented:
Wow, that's excellent! Thanks!
(just didn't know anything about mouse events etc.)

Regarding my second question:

I would like to have a procedure like 'addpoint(Sender: TObject);' instead of 'TForm1.BitBtn1Click(Sender: TObject);'
Now, when I go to the Object Inspector(of the DrawDataForm: TDrawGrid; object) in the Delphi environment(using Delphi 7), there are 2 tabs:
'properties' and 'events'. When I go to the 'events' tab, I can select one of the events like 'onMouseClick' etc.
This gives me a dropdown menu. Now the problem is I can only select the 'BitBtn1Click' there, so my guess is I should declare the procedure somewhere, but I don't know where since it's not an object like the button is
(type
  TForm1 = class(TForm)
    DrawDataForm: TDrawGrid;
    BitBtn1: TBitBtn;
    procedure BitBtn1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
)
and I can't get a forward declaration.
Hope this explains what I mean, I really think it's something simple I'm missing here..

Regards,
reynaerde
0
kretzschmarCommented:
>'properties' and 'events'. When I go to the 'events' tab, I can select one of the events >like 'onMouseClick'

you can one declared event on the dropdownmenu or create a new event-procedure by doubleclicking the empty evententry

meikl ;-)
0
reynaerdeAuthor Commented:
Great, thanks :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.