DBgrideh中有以下几条记录   
    
  记录1   
  记录2   
  记录3   
  记录4   
  记录5   
    
  我想实现的功能为:   
  当我选中   记录3   时,点一按钮就上移或下移记录3。

解决方案 »

  1.   

    首先在数据集中加上索引字段进行排序,例如设置IndexFieldNames
    然后在移动的时候更改排序字段的值就可以了
      

  2.   

    用adoquery吧
    下移
    if adoquery1.eof then
      adoquery1.next
    上移
    if adoquery1.bof then
      adoquery1.perior
      

  3.   

    有上移和下移的属性啊
    next 下一条记录
    prior 上一条记录
      

  4.   

    我也觉得用adoquery那个方便呀
      

  5.   

    楼主的问题看来只有lake_cx理解了,呵呵,其实描述得很清楚了,大家为什么为理解成那样呢
      

  6.   


    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;不知道有没有参考价值呀,很笨的方法。
      

  7.   

    为什么不用StringGrid来做这个事情呢