zoukankan      html  css  js  c++  java
  • DBGRID控件里可以实现SHIFT复选吗?怎么设置?

    ////////////////////////////////////////////////
    //    功能概述:公用的列表框选择框,是用DBGrid网格
    //
    //    注意事项:希望用Query查询列表
    //
    //    编写时间:shuszj
    //
    //    编写人员:2002.04.02
    //
    ////////////////////////////////////////
    unit uSelect_DBGrid;

    interface

    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, DB, ImgList, Grids, DBGrids, ComCtrls, StdCtrls, Mask, 
      ToolWin, DBTables, USELECT, XPMenu, Buttons, ExtCtrls, ADODB;

    const
      WM_SelectShare = WM_USER +10;          //公用列表

    type
      TSzjDBGrid = class(TDBGrid);
      TFmSelect_DBGrid = class(TFmSelect)
        procedure FormClose(Sender: TObject; var Action: TCloseAction);
        procedure FormCreate(Sender: TObject);
        procedure DBGrid1CellClick(Column: TColumn);
        procedure DBGrid1MouseUp(Sender: TObject; Button: TMouseButton;
          Shift: TShiftState; X, Y: Integer);
        procedure SpeedButton1Click(Sender: TObject);
      private
        m_sOne, m_sTwo :Integer;              //记下点击的当前的记录的行
        m_OneBMark, m_TwoBMark :TBookmark;    //记下点击的标签
        { Private declarations }
      public
        { Public declarations }
        procedure FPostion(Lft,Tp:integer);
      end;

    var
      FmSelect_DBGrid: TFmSelect_DBGrid;

    implementation

    {$R *.dfm}

    { TFmSelect_DBGrid }

    procedure TFmSelect_DBGrid.FPostion(Lft, Tp: integer);
    begin
      Self.Top :=Tp;
      Self.Left :=Lft;
    end;

    procedure TFmSelect_DBGrid.FormClose(Sender: TObject;
      var Action: TCloseAction);
    begin
      inherited;
      Action :=caFree;
      FmSelect_DBGrid :=nil;
    end;

    procedure TFmSelect_DBGrid.FormCreate(Sender: TObject);
    begin
      inherited;
    //  SetWindowLong(Self.Handle,GWL_EXSTYLE,WS_EX_TOOLWINDOW);       //在任务栏屏蔽
    end;

    procedure TFmSelect_DBGrid.DBGrid1CellClick(Column: TColumn);
    begin
      inherited;
      if (gSDataSet is TTable) or (gSDataSet is TQuery) then
      begin  
        if ThirdQuery.IsEmpty then
          Exit;
        m_OneBMark :=ThirdQuery.GetBookmark;
      end
      else
        if (gSDataSet is TADOTable) or (gSDataSet is TADOQuery) then
        begin
          if ADOThirdQuery.IsEmpty then
            Exit;
          m_OneBMark :=ADOThirdQuery.GetBookmark;
        end;
      m_sOne :=TSzjDBGrid(DBGrid1).Row;
    end;

    procedure TFmSelect_DBGrid.DBGrid1MouseUp(Sender: TObject;
      Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    begin
      inherited;
      if (gSDataSet is TTable) or (gSDataSet is TQuery) then
        if Button =mbleft then
        begin
          if ssShift in Shift then
          begin
            m_TwoBMark :=ThirdQuery.GetBookmark;
            m_sTwo :=TSzjDBGrid(DBGrid1).Row;
            if (m_sOne=0) or (m_OneBMark =nil) then
              Exit;
            with ThirdQuery do
            begin
              if m_sOne < m_sTwo then
              begin
                GotoBookmark(m_OneBMark);
                while not eof do
                begin
                  DBGrid1.SelectedRows.CurrentRowSelected :=True;
                  if CompareBookmarks(m_TwoBMark,GetBookmark) =0 then  
                    Exit;
                  Next;
                end;
              end
              else
              begin
                GotoBookmark(m_TwoBMark);
                while not eof do
                begin
                  DBGrid1.SelectedRows.CurrentRowSelected :=True;
                  if CompareBookmarks(m_OneBMark,GetBookmark) =0 then
                    Exit;
                  Next;
                end;
              end;
            end;
          end
          else
            CheckBox1.Checked :=False;
        end
      else
        if (gSDataSet is TADOTable) or (gSDataSet is TADOQuery) then
          if Button =mbleft then
          begin
            if ssShift in Shift then
            begin
              m_TwoBMark :=ThirdQuery.GetBookmark;
              m_sTwo :=TSzjDBGrid(DBGrid1).Row;
              if (m_sOne=0) or (m_OneBMark =nil) then
                Exit;
              with ThirdQuery do
              begin
                if m_sOne < m_sTwo then
                begin
                  GotoBookmark(m_OneBMark);
                  while not eof do
                  begin
                    DBGrid1.SelectedRows.CurrentRowSelected :=True;
                    if CompareBookmarks(m_TwoBMark,GetBookmark) =0 then  
                      Exit;
                    Next;
                  end;
                end
                else
                begin
                  GotoBookmark(m_TwoBMark);
                  while not eof do
                  begin
                    DBGrid1.SelectedRows.CurrentRowSelected :=True;
                    if CompareBookmarks(m_OneBMark,GetBookmark) =0 then
                      Exit;
                    Next;
                  end;
                end;
              end;
            end
            else
              CheckBox1.Checked :=False;
          end   
    end;

    procedure TFmSelect_DBGrid.SpeedButton1Click(Sender: TObject);
    begin
      inherited;
      if (gSDataSet is TTable) or (gSDataSet is TQuery) then
        if ThirdQuery.IsEmpty then
        begin
          Close;
          Exit;
        end
      else
        if (gSDataSet is TADOTable) or (gSDataSet is TADOQuery) then
          if ADOThirdQuery.IsEmpty then
          begin
            Close;
            Exit;
          end;
      gValue:=gSDataSet.Fields[0].AsString;
      SendMessage(gHandle,WM_SelectShare,0,0);
      Close;
    end;

    end.
    仔细看一下上面这个单元,里面就有写

  • 相关阅读:
    bash while until 循环用法
    微信小程序入门介绍
    jquery遍历
    jquery获取元素和DOM获取元素
    ul在div中水平居中效果
    一个文字在一个图片上水平居中,并且悬浮变大特效
    一个div在另一个div中垂直居中的方法
    layer插件的使用
    百度分享插件使用
    图标字体
  • 原文地址:https://www.cnblogs.com/jijm123/p/10247742.html
Copyright © 2011-2022 走看看