0

我有一个Listview我添加了TRect一个TEdit盒子并将其连接到一个单元格的地方。一切正常,但是当我调整窗口大小以使滚动条可见并更改滚动值时,编辑框未锁定到单元格。TRect(TEdit box) 与滚动值一起移动,并将字段留在我希望它保留的位置。

有什么建议么?

这里是OnMouseDown事件。

var
  pt: TPoint;
  ListItem: TListItem;
  lvHitInfo: TLVHitTestInfo;
  Ind: Integer;
  LVRect: TRect;
  ScrollOffsetHoriz: Integer;
  DeleteObject: TDeleteObject;
begin
  SendMessage(Handle, WM_SETREDRAW, WPARAM(False), 0);
  try
    pt := ListView.ScreenToClient(Mouse.CursorPos);

    ScrollOffsetHoriz := ListView.Items[0].DisplayRect(drBounds).Left;
    ListItem := ListView.GetItemAt(pt.X, pt.Y);
    FDeleteRow := -1;
    // over a sub item?
    if Assigned(ListItem) then
    begin
      FillChar(lvHitInfo, SizeOf(lvHitInfo), 0);
      lvHitInfo.pt := pt;
      if ListView.Perform(LVM_SUBITEMHITTEST, 0, LParam(@lvHitInfo)) <> -1 then
      begin
        LVRect.Left := ScrollOffsetHoriz;
        for Ind := 0 to lvHitInfo.iSubItem - 1 do
          LVRect.Left := LVRect.Left + ListView.Columns[Ind].Width;
        LVRect.Right := LVRect.Left + ListView.Columns[lvHitInfo.iSubItem].Width;
        LVRect.Top := ListItem.DisplayRect(drBounds).Top;
        LVRect.Bottom := ListItem.DisplayRect(drBounds).Bottom;

        FSelectedSubIndex := lvHitInfo.iSubItem;
        FSelectedIndex := lvHitInfo.iItem;
      end;
4

0 回答 0