记录移动 DBgrideh中有以下几条记录 记录1 记录2 记录3 记录4 记录5 我想实现的功能为: 当我选中 记录3 时,点一按钮就上移或下移记录3。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 首先在数据集中加上索引字段进行排序,例如设置IndexFieldNames然后在移动的时候更改排序字段的值就可以了 用adoquery吧下移if adoquery1.eof then adoquery1.next上移if adoquery1.bof then adoquery1.perior 有上移和下移的属性啊next 下一条记录prior 上一条记录 我也觉得用adoquery那个方便呀 楼主的问题看来只有lake_cx理解了,呵呵,其实描述得很清楚了,大家为什么为理解成那样呢 procedure Tfrm.btnupClick(Sender: TObject); //向上移动var a1, a2, a3, a4, a5: string;begin if X1 > 1 then begin with grid do begin a1 := Cells[1, X1 - 1]; a2 := Cells[2, X1 - 1]; a3 := Cells[3, X1 - 1]; a4 := Cells[4, X1 - 1]; a5 := Cells[5, X1 - 1]; Cells[1, X1 - 1] := Cells[1, X1]; Cells[2, X1 - 1] := Cells[2, X1]; Cells[3, X1 - 1] := Cells[3, X1]; Cells[4, X1 - 1] := Cells[4, X1]; Cells[5, X1 - 1] := Cells[5, X1]; Cells[1, X1] := a1; Cells[2, X1] := a2; Cells[3, X1] := a3; Cells[4, X1] := a4; Cells[5, X1] := a5; end; myRect.Left := 0; myRect.Top := X1 - 1; myRect.Right := 4; myRect.Bottom := X1 - 1; X1 := X1 - 1; grid.Selection := MyRect; grid.SetFocus; btnup.Enabled := True; btndown.Enabled := True; if X1 < 1 then btnup.Enabled := False; end;end;procedure Tfrm.btndownClick(Sender: TObject); //向下移动var a1, a2, a3, a4, a5: string;begin if X1 < grid.RowCount-1 then begin with grid do begin a1 := Cells[1, X1 + 1]; a2 := Cells[2, X1 + 1]; a3 := Cells[3, X1 + 1]; a4 := Cells[4, X1 + 1]; a5 := Cells[5, X1 + 1]; Cells[1, X1 + 1] := Cells[1, X1]; Cells[2, X1 + 1] := Cells[2, X1]; Cells[3, X1 + 1] := Cells[3, X1]; Cells[4, X1 + 1] := Cells[4, X1]; Cells[5, X1 + 1] := Cells[5, X1]; Cells[1, X1] := a1; Cells[2, X1] := a2; Cells[3, X1] := a3; Cells[4, X1] := a4; Cells[5, X1] := a5; end; myRect.Left := 0; myRect.Top := X1 + 1; myRect.Right := 4; myRect.Bottom := X1 + 1; X1 := X1 + 1; grid.Selection := MyRect; grid.SetFocus; btnup.Enabled := True; btndown.Enabled := True; if X1 >= grid.RowCount - 1 then btndown.Enabled := False; end;end;不知道有没有参考价值呀,很笨的方法。 为什么不用StringGrid来做这个事情呢 有个问题,不知怎么说出口~ 赵本山已与borland签协议:收购borland的ide部门。 DBGrid怎么实现给当前记录加底色? ClientDataSet的内容如何保存到dbf中? 怎样暂停递归,去打开另一个窗口? PChar类型和String类型--------在线等待!!!! 怎样改变inputQuery的字体? 图象横向和纵向的显示问题 Help 请教各大侠,我用ADO连接SQL SERVER数据库,在一个表单里有主从表两个表,但我的主表的字段如果LookUp另一个表时就会出错。 delphi 如何去掉 DBGrid 固定列 delphi7中的Sql语句问题
然后在移动的时候更改排序字段的值就可以了
下移
if adoquery1.eof then
adoquery1.next
上移
if adoquery1.bof then
adoquery1.perior
next 下一条记录
prior 上一条记录
procedure Tfrm.btnupClick(Sender: TObject); //向上移动
var
a1, a2, a3, a4, a5: string;
begin
if X1 > 1 then
begin
with grid do
begin
a1 := Cells[1, X1 - 1];
a2 := Cells[2, X1 - 1];
a3 := Cells[3, X1 - 1];
a4 := Cells[4, X1 - 1];
a5 := Cells[5, X1 - 1];
Cells[1, X1 - 1] := Cells[1, X1];
Cells[2, X1 - 1] := Cells[2, X1];
Cells[3, X1 - 1] := Cells[3, X1];
Cells[4, X1 - 1] := Cells[4, X1];
Cells[5, X1 - 1] := Cells[5, X1];
Cells[1, X1] := a1;
Cells[2, X1] := a2;
Cells[3, X1] := a3;
Cells[4, X1] := a4;
Cells[5, X1] := a5;
end;
myRect.Left := 0;
myRect.Top := X1 - 1;
myRect.Right := 4;
myRect.Bottom := X1 - 1;
X1 := X1 - 1;
grid.Selection := MyRect;
grid.SetFocus;
btnup.Enabled := True;
btndown.Enabled := True;
if X1 < 1 then
btnup.Enabled := False;
end;
end;
procedure Tfrm.btndownClick(Sender: TObject); //向下移动
var
a1, a2, a3, a4, a5: string;
begin
if X1 < grid.RowCount-1 then
begin
with grid do
begin
a1 := Cells[1, X1 + 1];
a2 := Cells[2, X1 + 1];
a3 := Cells[3, X1 + 1];
a4 := Cells[4, X1 + 1];
a5 := Cells[5, X1 + 1];
Cells[1, X1 + 1] := Cells[1, X1];
Cells[2, X1 + 1] := Cells[2, X1];
Cells[3, X1 + 1] := Cells[3, X1];
Cells[4, X1 + 1] := Cells[4, X1];
Cells[5, X1 + 1] := Cells[5, X1];
Cells[1, X1] := a1;
Cells[2, X1] := a2;
Cells[3, X1] := a3;
Cells[4, X1] := a4;
Cells[5, X1] := a5;
end;
myRect.Left := 0;
myRect.Top := X1 + 1;
myRect.Right := 4;
myRect.Bottom := X1 + 1;
X1 := X1 + 1;
grid.Selection := MyRect;
grid.SetFocus;
btnup.Enabled := True;
btndown.Enabled := True;
if X1 >= grid.RowCount - 1 then
btndown.Enabled := False;
end;
end;不知道有没有参考价值呀,很笨的方法。