Solved

Delphi 6 - TListView OnColumnRightClick Event get Incorrect Column Object

Posted on 2003-11-12
3
239 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…
Send secure, cloud-based, encrypted alerts and maintain HIPAA compliant messaging. Integrates priority & secure messaging into one application. Ensures IT, emergency respondents and healthcare professionals that their critical messages are never mis…

914 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

20 Experts available now in Live!

Get 1:1 Help Now