在 TListView 中更改选择后如何重置选择标记?
How to reset the selection mark after you've changed the selection in a TListView?
我有一个 TListView
虚拟模式,当我拖放一个项目时,我想将选择移动到新的项目位置。我这样做是清除选择,然后设置所需项目的 Selected 。没关系,但是有一个问题。发生这种情况后,如果我按住 shift 并单击一个项目(如多选),则列表的行为就像选择的开始是之前选择的项目而不是我选择的项目(Selected:= True)。
我尝试模拟点击,但在我移动鼠标后出现访问冲突:
procedure TForm1.ListDragDrop(Sender, Source: TObject; X, Y: Integer);
begin
List.Perform(WM_LBUTTONDOWN, MK_LBUTTON, [=10=]2E001E);
Sleep(10);
List.Perform(WM_LBUTTONUP, 0, [=10=]2E001E);
end;
选择新项目后,您也应该将其设置为焦点。但是,更重要的是,您需要向 ListView 发送 LVM_SETSELECTIONMARK
消息:
The selection mark is the item index from which a multiple selection starts.
例如:
procedure TForm1.ListDragDrop(Sender, Source: TObject; X, Y: Integer);
var
Item: TListItem;
begin
...
Item := ...; // the list item after it has been moved to its new position...
Item.Selected := True;
Item.Focused := True;
List.Perform(LVM_SETSELECTIONMARK, 0, Item.Index);
List.Invalidate;
...
end;
我有一个 TListView
虚拟模式,当我拖放一个项目时,我想将选择移动到新的项目位置。我这样做是清除选择,然后设置所需项目的 Selected 。没关系,但是有一个问题。发生这种情况后,如果我按住 shift 并单击一个项目(如多选),则列表的行为就像选择的开始是之前选择的项目而不是我选择的项目(Selected:= True)。
我尝试模拟点击,但在我移动鼠标后出现访问冲突:
procedure TForm1.ListDragDrop(Sender, Source: TObject; X, Y: Integer);
begin
List.Perform(WM_LBUTTONDOWN, MK_LBUTTON, [=10=]2E001E);
Sleep(10);
List.Perform(WM_LBUTTONUP, 0, [=10=]2E001E);
end;
选择新项目后,您也应该将其设置为焦点。但是,更重要的是,您需要向 ListView 发送 LVM_SETSELECTIONMARK
消息:
The selection mark is the item index from which a multiple selection starts.
例如:
procedure TForm1.ListDragDrop(Sender, Source: TObject; X, Y: Integer);
var
Item: TListItem;
begin
...
Item := ...; // the list item after it has been moved to its new position...
Item.Selected := True;
Item.Focused := True;
List.Perform(LVM_SETSELECTIONMARK, 0, Item.Index);
List.Invalidate;
...
end;