共计 1006 个字符,预计需要花费 3 分钟才能阅读完成。
//ListBox的项上移下移函数
procedure MoveUpDown(ListBox: TListBox; UpDownType: AnsiString);
var
IndexCount, SelectedIndex: Integer;
begin
try
if ListBox = nil then Exit;
IndexCount := ListBox.Items.Count;
if IndexCount = 0 then Exit;
SelectedIndex := ListBox.ItemIndex;
if SelectedIndex = -1 then Exit;
if UpperCase(UpDownType) = UpperCase(‘Up’) then
begin
if (SelectedIndex – 1) < 0 then Exit;
ListBox.Items.Move(SelectedIndex, (SelectedIndex - 1));
ListBox.ItemIndex := SelectedIndex - 1;
ListBox.Selected[SelectedIndex - 1] := True;
end;
if UpperCase(UpDownType) = UpperCase('Down') then
begin
if (SelectedIndex + 1) > (IndexCount -1) then Exit;
ListBox.Items.Move(SelectedIndex, (SelectedIndex + 1));
ListBox.ItemIndex := SelectedIndex + 1;
ListBox.Selected[SelectedIndex + 1] := True;
end;
except
end;
end;
procedure ListBoxSetFocus(ListBox: TListBox);
var
I, IndexCount: Integer;
begin
try
if ListBox = nil then Exit;
IndexCount := ListBox.Items.Count;
if IndexCount = 0 then Exit;
for I := 0 to IndexCount – 1 do
ListBox.Selected[i] := False;
ListBox.Selected[0] := true;
except
end;
end;
用法,例:
MoveUpDown(ListBox1,’Up’);
MoveUpDown(ListBox1,’Down’);