Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Listview

Posted on 2004-09-19
10
Medium Priority
?
823 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 300 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 300 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
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…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

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