procedure MoveBy(moves:Integer); //moves为负表上多,为正表下移 var id:integer; begin if moves=0 then exit;//不移动 if checklistbox1.itemindex=-1 then exit; //检查有没有行被选取 id:=checklistbox1.itemindex; if moves<0 then //上移 if id+moves<0 then moves:=-id; //最上行 if moves>0 then //下移 if id+moves>checklistbox1.count then moves:=checklistbox1.count-id; //最下行 checklistbox1.items.move(id,id+moves); checklistbox1.itemindex:=id-1; end;
checklistbox.checked[i] 是判断第i行是否选择中。 你直接调用Moveby(-1),是代表将当前选择中的行上移一行 如果用打勾的,你可以将进行判断: 下面将第一个打勾的上多一行 for i:=0 to checklistbox.count-1 do if checklistbox.checked[i] then begin checklistbox.selected[i]:=true; moveby(-1); break; end;//总之,使用Move功能,将第几行,移动到第几行
procedure TForm1.FormCreate(Sender: TObject); begin UpDown1.Max := CheckListBox1.Items.Count - 1; end;procedure TForm1.UpDown1Click(Sender: TObject; Button: TUDBtnType); var I, J: Integer; Str: string; bl: Boolean; begin for I := 0 to CheckListBox1.Items.Count - 1 do begin if CheckListBox1.Selected[I] then begin if ((I =0) and (Button = btNext) )or ((I = CheckListBox1.Items.Count ) and (Button = btPrev)) then begin Break; end; J := I; if Button = btNext then Dec(J) else Inc(J); CheckListBox1.Selected[I] := False; bl := CheckListBox1.Checked[I]; Str := CheckListBox1.Items[I]; CheckListBox1.Items.Delete(I); CheckListBox1.Items.Insert(J, Str); CheckListBox1.Selected[J] := True; CheckListBox1.Checked[J] := True; Break; end; end;end;procedure TForm1.CheckListBox1Click(Sender: TObject); var I: Integer; begin for I := 0 to CheckListBox1.Items.Count - 1 do begin if CheckListBox1.Selected[I] then begin UpDown1.Position := UpDown1.Max - I; end; end; end;
var
id:integer;
begin
if moves=0 then exit;//不移动
if checklistbox1.itemindex=-1 then exit; //检查有没有行被选取
id:=checklistbox1.itemindex;
if moves<0 then //上移
if id+moves<0 then moves:=-id; //最上行
if moves>0 then //下移
if id+moves>checklistbox1.count then moves:=checklistbox1.count-id; //最下行
checklistbox1.items.move(id,id+moves);
checklistbox1.itemindex:=id-1;
end;
checklistbox1.itemindex:=id+moves;
我已经恨不得搞2个按牛实现updown 的功能了.都写好了,就差不知道checklistbox选中是怎么判断的了.
checklistbox.checked[i] 是判断是否钩选.
我要的功能是,只要选中 一条,未钩选的移动.
你直接调用Moveby(-1),是代表将当前选择中的行上移一行
如果用打勾的,你可以将进行判断:
下面将第一个打勾的上多一行
for i:=0 to checklistbox.count-1 do
if checklistbox.checked[i] then
begin
checklistbox.selected[i]:=true;
moveby(-1);
break;
end;//总之,使用Move功能,将第几行,移动到第几行
begin
UpDown1.Max := CheckListBox1.Items.Count - 1;
end;procedure TForm1.UpDown1Click(Sender: TObject; Button: TUDBtnType);
var
I, J: Integer;
Str: string;
bl: Boolean;
begin
for I := 0 to CheckListBox1.Items.Count - 1 do
begin
if CheckListBox1.Selected[I] then
begin
if ((I =0) and (Button = btNext) )or ((I = CheckListBox1.Items.Count ) and (Button = btPrev)) then
begin
Break;
end;
J := I;
if Button = btNext then
Dec(J)
else
Inc(J);
CheckListBox1.Selected[I] := False;
bl := CheckListBox1.Checked[I];
Str := CheckListBox1.Items[I];
CheckListBox1.Items.Delete(I);
CheckListBox1.Items.Insert(J, Str);
CheckListBox1.Selected[J] := True;
CheckListBox1.Checked[J] := True;
Break;
end;
end;end;procedure TForm1.CheckListBox1Click(Sender: TObject);
var
I: Integer;
begin
for I := 0 to CheckListBox1.Items.Count - 1 do
begin
if CheckListBox1.Selected[I] then
begin
UpDown1.Position := UpDown1.Max - I;
end;
end;
end;