Solved

Delphi 6 - TListView OnColumnRightClick Event get Incorrect Column Object

Posted on 2003-11-12
3
246 Views
Last Modified: 2010-04-03
I have a Listview in my Application, it is displayed in Report Mode with ShowColumnHeaders set to True, I have code in the OnColumnRightClick Event which makes use of the Column Object,

But the Column Object Passed to the Event is incorrect if you have scrolled horizontally, Delphi seems to return the column which would have been there if you hadn't have scrolled.

Can't think of a way around this, thought maybe find out how far I have scrolled and then add up all the column widths and therefore being able to manually determine the column which was clicked - that didn't work because TListView does not expose the Scrollbars and I dont know how else to find out how far I have scrolled.

NOTE: OnColumnClick event dosn't have this problem but I already use this Event to sort my list view.

Any suggestions?

Thanks,

-D
0
Comment
Question by:DRyall
3 Comments
 
LVL 27

Accepted Solution

by:
kretzschmar earned 50 total points
ID: 9731227
well seems to be a bug

following workaround

procedure TForm1.ListView1ColumnRightClick(Sender: TObject;
  Column: TListColumn; Point: TPoint);
var
  i,cw,cc : integer;

  col : TListColumn;
begin
  col := nil;
  i := getscrollpos(listview1.Handle,sb_horz); //currentscrollbarpos
  i := i + point.x;
  cc := 0;
  cw := 0;
  while (cc < listview1.Columns.Count) and
        (cw < i) do
  begin
    cw := cw + listview1.Columns[cc].width; //add width
    if cw < i then
      inc(cc);
  end;
  if (cc < listview1.Columns.Count) then
    col := listview1.Columns[cc];

  if assigned(col) then
    //do your action
    showmessage(Col.Caption);
end;

meikl ;-)
0

Featured Post

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!

Question has a verified solution.

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

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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

735 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