procedure TCnComponentSelectorForm.actDeleteExecute(Sender: TObject);
var
i: Integer;
begin
BeginUpdateList;
try
for i := 0 to lbDest.Items.Count - 1 do // 只有当前过滤列表中有的才加入到左边
if lbDest.Selected[i] and (CurrList.IndexOf(lbDest.Items[i]) >= 0) then
lbSource.Items.AddObject(lbDest.Items[i], lbDest.Items.Objects[i]);
for i := lbDest.Items.Count - 1 downto 0 do
if lbDest.Selected[i] then
lbDest.Items.Delete(i);
finally
UpdateSourceOrders;
EndUpdateList;
end;
end;
只不过处理的对象对调了,那就弄一个方法如下:
procedure MoveFieldToOther(aLstSource, aLstDest: TListBox);
var
i: Integer;
begin
BeginUpdateList;
try
for i := 0 to aLstSource.Items.Count - 1 do // 只有当前过滤列表中有的才加入到左边
if aLstSource.Selected[i] and (CurrList.IndexOf(aLstSource.Items[i]) >= 0) then
aLstDest.Items.AddObject(aLstSource.Items[i], aLstSource.Items.Objects[i]);
for i := aLstSource.Items.Count - 1 downto 0 do
if aLstSource.Selected[i] then
aLstSource.Items.Delete(i);
finally
UpdateSourceOrders;
EndUpdateList;
end;
end;