ListView1的属性MultiSelect设置为true;var i:Integer; List:TList; begin List:=TList.Create; for i:=0 to ListView1.Items.Count-1 do begin if ListView1.Items[i].Selected then begin List.Add(ListView1.Items[i]); //添加到list里 end; end; List.Free; end;
selections[]里存放的就是选择的节点列表
灵异事件?为什么我这里有?selections?
Selections property (TCustomTreeView)Returns nodes selected.Delphi syntax:property Selections[Index: Integer]: TTreeNode;C++ syntax:__property TTreeNode* Selections[int Index] = {read=GetSelection};DescriptionSelections returns one of selected nodes. The maximum value of Index is SelectionCount-1. If more than one node is selected, Selections[0] is the primary selected node. This node is the starting point for extended selections if MultiSelectStyle includes msShiftSelect.
var i:Integer; begin for i:=0 to TreeView1.SelectionCount-1 do begin showmessage(TreeView1.Selections[i].Text); //在这里把值添加到list里 end; end;
i:Integer;
List:TList;
begin
List:=TList.Create;
for i:=0 to ListView1.Items.Count-1 do
begin
if ListView1.Items[i].Selected then
begin
List.Add(ListView1.Items[i]); //添加到list里
end;
end;
List.Free;
end;
i:Integer;
begin
for i:=0 to TreeView1.SelectionCount-1 do
begin
showmessage(TreeView1.Selections[i].Text); //在这里把值添加到list里
end;
end;