Solved

select & popup

Posted on 1997-04-17
2
230 Views
Last Modified: 2010-04-04
How can I make right-clicking a TStringGrid select the cell the mouse is over and just then pop up the popupmenu?
0
Comment
Question by:alona041797
2 Comments
 
LVL 1

Accepted Solution

by:
CFantin earned 50 total points
ID: 1335445
Try this bit of code.

You need to place a popup menu on your form and assign it to your
StringGrids popup menu.

procedure TForm1.StringGrid1MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var ACol, ARow: LongInt;
begin
  {Check if the mouse button pressed was the right button}
  if Button = mbRight then
  begin
    {Get the Row and Col click on}
    StringGrid1.MouseToCell(X, Y, ACol, ARow);
    {Check that the user clicked on a valid Row and Col}
    if (ACol <> - 1) and (ARow <> - 1) then
    begin
      {Check if the user has not clicked on a fixed col or row
      as you cannot select a fixed col or row}
      if (StringGrid1.FixedCols <= ACol) and (StringGrid1.FixedRows <= ARow) then
      begin
        {Make the current selection equal to the Row and Col clicked on}
        StringGrid1.Col := ACol;
        StringGrid1.Row := ARow;
      end;
    end
  end;
end;

0
 
LVL 2

Author Comment

by:alona041797
ID: 1335446
Thanks a lot.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

Suggested Solutions

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

831 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