• Delphi 关于DBGrid多选删除(shitf多选,ctrl多选)


    ////删除多选记录

    procedure THistoryForm.DeleteButtonClick(Sender: TObject);
    var
      tempBookMark:TbookMark;
      i:integer;
    begin
      if dbgrid1.SelectedRows.Count <= 0 Then
      begin
        MessageBox(Handle,'请选择您要删除的记录','提示',MB_OK);
        Exit;
      end;

      If MessageBox(Handle,'删除后数据将不可恢复,您确定要删除吗?','提示',mb_iconinformation+mb_YesNo)=IdYes Then
      Begin
        i:=0;
        DBGrid1.Datasource.Dataset.DisableControls;
        While i<=dbgrid1.SelectedRows.Count - 1 Do
        Begin
          DBGrid1.Datasource.Dataset.Bookmark:=dbgrid1.SelectedRows.Items[i];//重要的在这里,取得BOOKMARK
          TempBookmark:=DBGrid1.Datasource.Dataset.GetBookmark;
          DBGrid1.Datasource.Dataset.GotoBookmark(TempBookmark);

          with ADOQuery3 do
          begin
            Close;
            SQL.Clear;
            SQL.Add('delete from his where id=:a');
           Parameters.ParamByName('a').Value:=Dbgrid1.DataSource.DataSet.fieldbyname('id').AsInteger;
            ExecSql;
          end;
          DBGrid1.Datasource.Dataset.FreeBookmark(TempBookmark);     //释放BOOKMARK
          inc(i);   //下一个选择记录
        End;
        DBGrid1.Datasource.Dataset.EnableControls;
        Act_ShowCTInfo(LBName.Caption);
        Memo1.Clear;
      end;
    end;

    //定义全局变量

    var

      blSelect: Boolean;
      BookMark: TBookMark;
      CurrNo, OldNo: integer;

    /////////按Shift多选

    procedure THistoryForm.DBGrid1MouseUp(Sender: TObject;
      Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    begin //实现 Shift+鼠标左键单击 多选
      if Button = mbLeft then
      begin
        if not blSelect then
        begin
          BookMark := ADOQuery1.GetBookMark;
          OldNo := ADOQuery1.RecNo;
          blSelect := True;
          Exit;
        end
        else
        begin
          if ssShift in Shift then
          begin
            CurrNo := ADOQuery1.RecNo;
            ADOQuery1.DisableControls;
            ADOQuery1.GotoBookmark(BookMark);
            DBGrid1.SelectedRows.CurrentRowSelected := True;
            if CurrNo > OldNo then
            begin
              while CurrNo > ADOQuery1.RecNo do
              begin
                DBGrid1.SelectedRows.CurrentRowSelected := True;
                ADOQuery1.Next;
              end;
            end
            else
            begin
              while CurrNo < ADOQuery1.RecNo do
              begin
                DBGrid1.SelectedRows.CurrentRowSelected := True;
                ADOQuery1.Prior;
              end;
            end;
            ADOQuery1.EnableControls;
            ADOQuery1.FreeBookmark(BookMark);
            blSelect := False;
            CurrNo := 0;
            OldNo := 0;
          end
          else
          begin
            BookMark := ADOQuery1.GetBookMark;
            OldNo := ADOQuery1.RecNo;
            blSelect := True;
            Exit;
          end;
        end;
      end;
    end;

  • 相关阅读:
    js-html音乐播放
    CSS-实现倒影效果box-reflect
    html-屏蔽按键盘空格键是滚动条向下滚动
    html-禁用右键、键盘F12、网页上选取内容、复制、粘贴
    js-回调函数
    man bash 关于shell的应有尽有 语法、快捷键...
    source vs export AND ctrl d vs ctrl z
    技术----阳春
    限流 降级
    linux TOP
  • 原文地址:https://www.cnblogs.com/jijm123/p/8087933.html
Copyright © 2020-2023  润新知