Solved

Listview

Posted on 2004-09-19
10
786 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
 
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
This video discusses moving either the default database or any database to a new volume.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

705 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now