delphi ListBox的项上移下移函数

169次阅读
没有评论

共计 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’);

正文完
 
admin
版权声明:本站原创文章,由 admin 2014-02-21发表,共计1006字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。