Solved

Listview

Posted on 2004-09-19
10
796 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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Wininet read php file from internet issue 6 91
Convert MS Word document to a PDF file 9 82
how to change, disabled button color FMX ? 1 33
enhance the following code 3 32
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…
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

810 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