- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要将多个项目拖放到我的 Tlistbox
中。
我所指的代码是
var
StartingPoint : TPoint;
implementation
...
procedure TForm1.FormCreate(Sender: TObject) ;
begin
ListBox1.DragMode := dmAutomatic;
end;
procedure TForm1.ListBox1DragDrop(Sender, Source: TObject; X, Y: Integer) ;
var
DropPosition, StartPosition: Integer;
DropPoint: TPoint;
begin
DropPoint.X := X;
DropPoint.Y := Y;
with Source as TListBox do
begin
StartPosition := ItemAtPos(StartingPoint,True) ;
DropPosition := ItemAtPos(DropPoint,True) ;
Items.Move(StartPosition, DropPosition) ;
end;
end;
procedure TForm1.ListBox1DragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean) ;
begin
Accept := Source = ListBox1;
end;
procedure TForm1.ListBox1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer) ;
begin
StartingPoint.X := X;
StartingPoint.Y := Y;
end;
from here .
它工作正常,但我需要实现的是这样的 .
为什么我想要这个是因为这些列表框项目有一定的对应顺序。因此,我想启用多个拖放,而不是手动选择每个项目并将其拖放。
任何有关我如何实现这一目标的意见都将受到赞赏。
如果可以使用其他组件,也可以建议使用其他组件。
最佳答案
要做好这一点是非常棘手的(请参阅我对此答案的第一次修订,了解如何出错的示例)。
这是一种相当容易理解的方法,可以通过以下方式解决问题:
procedure TForm1.ListBox1DragDrop(Sender, Source: TObject; X, Y: Integer);
var
ListBox: TListBox;
i, TargetIndex: Integer;
SelectedItems: TStringList;
begin
Assert(Source=Sender);
ListBox := Sender as TListBox;
TargetIndex := ListBox.ItemAtPos(Point(X, Y), False);
if TargetIndex<>-1 then
begin
SelectedItems := TStringList.Create;
try
ListBox.Items.BeginUpdate;
try
for i := ListBox.Items.Count-1 downto 0 do
begin
if ListBox.Selected[i] then
begin
SelectedItems.AddObject(ListBox.Items[i], ListBox.Items.Objects[i]);
ListBox.Items.Delete(i);
if i<TargetIndex then
dec(TargetIndex);
end;
end;
for i := SelectedItems.Count-1 downto 0 do
begin
ListBox.Items.InsertObject(TargetIndex, SelectedItems[i], SelectedItems.Objects[i]);
ListBox.Selected[TargetIndex] := True;
inc(TargetIndex);
end;
finally
ListBox.Items.EndUpdate;
end;
finally
SelectedItems.Free;
end;
end;
end;
现在,可以通过一系列 Move
调用来完成此操作,但很难做到正确。每次移动时,所选项目的所有索引都会发生变化。我上面给出的方法是我解决这个问题的首选方法。顺便说一句,我最近在 TreeView 的上下文中解决了完全相同的问题,而且这也非常棘手!
关于Delphi列表框拖放多个项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9176684/
我在这里有一个我想要做的事情的例子:http://jsbin.com/OwoYAlEQ/1/edit 这是我的 HTML: person one person two person three per
我想知道是否有人知道是否有一个预先制定的解决方案:我在 ASP.net 网站上有一个列表,我希望用户能够通过拖放对列表进行重新排序。此外,我希望有第二个列表,用户可以将第一个列表中的项目拖到其中。 到
我想知道是否有人知道是否有一个预先制定的解决方案:我在 ASP.net 网站上有一个列表,我希望用户能够通过拖放对列表进行重新排序。此外,我希望有第二个列表,用户可以将第一个列表中的项目拖到其中。 到
我在我的 Web 应用程序中使用 Ajax ControlToolkit 中的 ModalPopupExtender。我将其 Drag 属性设置为 true,但是当我拖动弹出面板并将其放到新位置时,它
所以,基于this answer ,我有一组可以拖放并卡入到位的 div。唯一的问题是,可拖动的 div 具有不同的高度,我需要它们始终捕捉到目标的底部,而不是顶部。 您可以在this JsFiddl
我一直在使用 Bea 的解决方案 here一段时间后发现它非常有帮助。现在我遇到的问题是,当我将项目拖放到另一个 ListView 控件中或拖放到另一个 ListView 控件中,并且我想在拖动“期间
我试图在使用 QTreeWidget.setItemWidget() 重新父级(拖放)后将小部件放入 QTreeWidgetItem 但是,如果编译以下代码,结果是 QTreeWidgetItem 内
这是场景,我使用的是prototype和scriptaculous,但我相信jquery也会有同样的问题。我在相对定位的 div 中有一个可拖动图像的列表。问题是我无法将图像拖出父 div...好吧.
我正在使用一个普通(Bootstrap)表,我想在其中包含可排序的行。我正在使用 Angular CDK (DragDropModule) 来实现排序/排序。但是,当拖动行时,它会扭曲宽度,因为 cd
我正在尝试在我的 UICollectionView 中实现拖放机制,这与在快捷方式应用程序中重新排序快捷方式的组件非常相似。 截至目前,行为是当您开始拖动时,会留下一个透明的单元格 View ,而另一
我有以下 Jquery UI 拖放 jsfiddle https://jsfiddle.net/zoojsfiddle/ud96jdcp/ 具有
我希望创建一个基于网络的“公告板”,可以这么说,用户可以在其中创建/删除/拖放“图钉”,而不允许重叠“图钉”。 这是一个图表,应该有助于说明我正在尝试创建的内容: 'pins' 可能已创建双击;他们会
我是一名优秀的程序员,十分优秀!