Solved

Delphi 6 - TListView OnColumnRightClick Event get Incorrect Column Object

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Read/Write registry value from HKEY_LOCAL_MACHINE 5 178
Delphi OLE Error 8 84
Delphi cmd execution 6 42
Delphi Form ownership 4 54
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 The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video discusses moving either the default database or any database to a new volume.

743 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

11 Experts available now in Live!

Get 1:1 Help Now