调用方法

procedure TfrmDataImport.B_ExcelDownClick(Sender: TObject);
begin
UpDownTVItem(TV_Import, 2);
end; procedure TfrmDataImport.B_ExcelUpClick(Sender: TObject);
begin
UpDownTVItem(TV_Import, 1);
end;

  

上下移动函数

procedure TfrmDataImport.UpDownTVItem(aTV : TTreeView; UpDown : Integer);
var
tmText : String;
tmP : Pointer;
i, AddV : Integer;
tmAsk : Boolean;
begin
// UpDown : 1 Up Other Down
if Assigned(aTV.Selected) then
begin
tmAsk := False;
if UpDown = then
begin
AddV := -;
if aTV.Selected.Index > then
tmAsk := True;
end
else
begin
AddV := ;
if aTV.Selected.Index < aTV.Items.Count - then
tmAsk := True;
end; if tmAsk then
begin
i := aTV.Selected.Index;
tmText := aTV.Selected.Text;
tmP := aTV.Selected.Data;
aTV.Items.Item[i].Text := aTV.Items.Item[i + AddV].Text;
aTV.Items.Item[i].Data := aTV.Items.Item[i + AddV].Data;
aTV.Items.Item[i + AddV].Text := tmText;
aTV.Items.Item[i + AddV].Data := tmP;
aTV.Items.Item[i + AddV].Selected := True;
end;
end;
end;
05-07 15:25