Solved

Listview

Posted on 2004-09-19
10
804 Views
Last Modified: 2010-04-05
How can i find out if the user right clicked on the column header of a listview - i know i can use oncolumnclick to find out when the user left clicked on the column heading but it does not give information on the right mouse button.
0
Comment
Question by:tayto
  • 4
  • 2
  • 2
  • +1
10 Comments
 
LVL 11

Expert Comment

by:calinutz
ID: 12097797
procedure TForm1.ListView1ColumnRightClick(Sender: TObject;
  Column: TListColumn; Point: TPoint);
begin

end;
0
 
LVL 11

Expert Comment

by:calinutz
ID: 12097804
procedure TForm1.ListView1ColumnRightClick(Sender: TObject;
  Column: TListColumn; Point: TPoint);
begin
ShowMessage(IntToStr(column.Index));
end;
0
 

Author Comment

by:tayto
ID: 12097952
ListView does not have any event of ListView1ColumnRightClick(Sender: TObject;
 Column: TListColumn; Point: TPoint);

I am using Delphi 4 Professional.
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 12

Accepted Solution

by:
Ivanov_G earned 100 total points
ID: 12099590
procedure TForm1.ListView1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if Button = mbRight then
    begin
      // find what do you have at (X,Y)
    end;
end;
0
 
LVL 14

Assisted Solution

by:Pierre Cornelius
Pierre Cornelius earned 100 total points
ID: 12100088
You can use the MouseDown event as suggested by IvanovG or alternatively derive your own descendant class from the TDBGrid class. The advantage of deriving a new class instead is that you can register it as a new component and have it available as a design-time component which you can drop on the forms and have access to the new event ("OnCustomTitleClick" in below example):

e.g. 1 - Use of Mousedown event:
=====================
procedure TForm1.ListView1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var Col: TColumn;
begin
  if Button = mbRight then
    begin
      Col:= Columns[RawToDataColumn(Cell.X)];
      ShowMessage(
      // find what do you have at (X,Y)
    end;
end;

e.g.2 - New derived custom grid class
========================
  TCustomTitleClickEvent = procedure (Column: TColumn; Button: TMouseButton;
                                 Shift: TShiftState; X, Y: Integer) of object;

  TMyDBGrid = class(TDBGrid)
    private
      FOnCustomTitleClick: TCustomTitleClickEvent;
    protected
      procedure MouseUp(Button: TMouseButton; Shift: TShiftState;
                        X, Y: Integer); override;
      procedure DoCustomTitleClick(Column: TColumn; Button: TMouseButton;
                                   Shift: TShiftState; X, Y: Integer);

    published
      property OnCustomTitleClick: TCustomTitleClickEvent
                                     read FOnCustomTitleClick
                                     write FOnCustomTitleClick;
      property FixedRows;
  end;

procedure TMyDBGrid.MouseUp(Button: TMouseButton; Shift: TShiftState; X,
  Y: Integer);
var
  Cell: TGridCoord;
begin
  inherited;
  Cell := MouseCoord(X,Y);

  if Cell.Y = 0 then
    DoCustomTitleClick(Columns[RawToDataColumn(Cell.X)], Button, Shift, x,y);
end;

procedure TMyDBGrid.DoCustomTitleClick(Column: TColumn;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
  Cell: TGridCoord;
begin
  if Assigned(FOnCustomTitleClick)
    then FOnCustomTitleClick(Column, Button, Shift, X, Y);
end;


Kind regards
Pierre
0
 
LVL 14

Expert Comment

by:Pierre Cornelius
ID: 12100093
Sorry, I meant to have the following for example 1:

  if Button = mbRight then
    begin
      Col:= DBGrid1.Columns[DBGrid1.MouseCoord(x,y).x-1];
      ShowMessage('Column Title: '+ Col.Title.Caption+#13+
                  'Column Field: '+ Col.FieldName);
    end;
0
 

Author Comment

by:tayto
ID: 12103763
PierreC - i'm a little confused.  Derive from DBGrid to use a listview?


Ivanov_G  - i can find (X,Y) but translating it into which column title was clicked is the part i am having problems with
0
 

Author Comment

by:tayto
ID: 12103801
Ivanov_G - actually, using if Button = mbRight then in the mousedown event does not work when i click on the actual listview column title, only works when i click on a cell
0
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 12105079
Yep... I tried it. OnColumnClick catch only left button and OnMouseDown/Up is not capture on header click ... Bad ...
0
 

Author Comment

by:tayto
ID: 12108296
It's ok - i finally worked out how to do it.  Had to write a sub-class of the component but it did the trick.

I decided to just split the points between both Ivanov_G and PierreC as they both at least tried to help.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

830 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