Solved

Listview

Posted on 2004-09-19
10
819 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month7 days, 11 hours left to enroll

632 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