|
发表于 2020-4-17 20:30:01
|
显示全部楼层
改了一下
function TListViewX.GetItemAtX(X, Y: integer;
var Col: integer): TListItem;
var
i, n, RelativeX, ColStartX: Integer;
ListItem: TlistItem;
OldRowSelect:Boolean;
Found:Boolean;
begin
Result := GetItemAt(X, Y);
if (not RowSelect) and (Result <> nil) then
begin
Col := 0; // First column
end
else if (ViewStyle = vsReport)
and (TopItem <> nil) then
begin
// First, let's try to find the row
//ListItem := GetItemAt(TopItem.Position.X, Y);
//save rowselect setting
OldRowSelect := RowSelect;
RowSelect := True;
ListItem := GetItemAt(X, Y);
//Restore rowselect setting;
RowSelect := OldRowSelect;
if ListItem <> nil then
begin
// Now let's try to find the Column
RelativeX := X - ListItem.Position.X - BorderWidth;
// ColStartX := Columns[0].Width;
ColStartX:=0;
n := Columns.Count - 1;
for i := 0 to n do
begin
if RelativeX < ColStartX + Columns[i].Width then
begin
Result:=ListItem;
Col:=i;
break;
end;
{ if RelativeX <= ColStartX +
StringWidth(ListItem.SubItems[i - 1]) then
begin
Result := ListItem;
Col := i;
break;
end; //if}
Inc(ColStartX, Columns[i].Width);
end; //for
// Col:=i;
end; //if
end; //if
end;
|
|