| |

VerySource

 Forgot password?
 Register
Search
Author: woshibate

How does listview know, which column is the mouse click?

[Copy link]

1

Threads

13

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2020-4-17 20:30:01
| Show all posts
Changed a bit

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;
Reply

Use magic Report

1

Threads

6

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

 Author| Post time: 2020-5-2 13:15:01
| Show all posts
Problem solved, thanks to the code ofjk66255
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list