我想把我选种的dbgrid中的一行数据移动到上一行,该怎么写代码啊 
保存以后数据库中的次数是不是和他是 一样的呢,求解

解决方案 »

  1.   

    我有个例子,给你吧
    procedure TFplzj.bsSkinDBGrid1DrawColumnCell(Sender: TObject;
      const Rect: TRect; DataCol: Integer; Column: TbsColumn;
      State: TGridDrawState);
    begin
    if startselect then
    begin
    if endselect then
      begin
        if (table1.RecNo>=startrecord)and(table1.RecNo<=endrecord) then
        begin
            with self.bsSkinDBGrid1 do
            begin
            canvas.Font.Color:=clyellow;
            canvas.Brush.Color:=clnavy;
            defaultdrawcolumncell(rect,datacol,column,state);
            end;
        end;
      end else
      begin
        if table1.RecNo=startrecord then
        begin
            with self.bsSkinDBGrid1 do
            begin
            canvas.Font.Color:=clyellow;
            canvas.Brush.Color:=clnavy;
            defaultdrawcolumncell(rect,datacol,column,state);
            end
        end;
      end;
    end;
    end;
      

  2.   

    给错了,再发一次
    procedure TFstudent.bsSkinSpeedButton1Click(Sender: TObject);
    var
    str,str1:string;
    begin///向上
    if dm.ADOTstudent.RecordCount>1 then
       begin
       str:=dm.ADOTstudent.fieldbyname('姓名').AsString;
       dm.ADOTstudent.Prior;
       if not dm.ADOTstudent.Bof then
       begin
       str1:=dm.ADOTstudent.fieldbyname('姓名').AsString;
       dm.ADOTstudent.Edit;
       dm.ADOTstudent.FieldByName('姓名').AsString:=str;
       dm.ADOTstudent.Post;
       dm.ADOTstudent.Next;
       dm.ADOTstudent.Edit;
       dm.ADOTstudent.FieldByName('姓名').AsString:=str1;
       dm.ADOTstudent.Post;
       dm.ADOTstudent.Prior;
       end;
       end;
    end;procedure TFstudent.bsSkinSpeedButton2Click(Sender: TObject);
    var
    str,str1:string;
    begin//向下
    if dm.ADOTstudent.RecordCount>1 then
       begin
       str:=dm.ADOTstudent.fieldbyname('姓名').AsString;
       dm.ADOTstudent.Next;
       if not dm.ADOTstudent.Eof then
       begin
       str1:=dm.ADOTstudent.fieldbyname('姓名').AsString;
       dm.ADOTstudent.Edit;
       dm.ADOTstudent.FieldByName('姓名').AsString:=str;
       dm.ADOTstudent.Post;
       dm.ADOTstudent.Prior;
       dm.ADOTstudent.Edit;
       dm.ADOTstudent.FieldByName('姓名').AsString:=str1;
       dm.ADOTstudent.Post;
       dm.ADOTstudent.Next;
       end;
       end;
    end;