如题?

解决方案 »

  1.   

    设置DBGRID的属性:
    Optiongs:dgMultiSelect设置为true;
      

  2.   

    设置DBGRID的属性:
    Optiongs:dgMultiSelect设置为true然后用按CRTL用鼠标选择就可以了
      

  3.   

    设置DBGRID的属性:
    DBGRID.Options.dgMultiSelect设置为true然后用按SHIFT用鼠标选择就可以了
      

  4.   

    ////////////////////////////////////////////////
    //    功能概述:公用的列表框选择框,是用DBGrid网格
    //
    //    注意事项:希望用Query查询列表
    //
    //    编写时间:shuszj
    //
    //    编写人员:2002.04.02
    //
    ////////////////////////////////////////
    unit uSelect_DBGrid;interfaceuses
      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 :TBook;    //记下点击的标签
        { 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.GetBook;
      end
      else
        if (gSDataSet is TADOTable) or (gSDataSet is TADOQuery) then
        begin
          if ADOThirdQuery.IsEmpty then
            Exit;
          m_OneBMark :=ADOThirdQuery.GetBook;
        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.GetBook;
            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
                GotoBook(m_OneBMark);
                while not eof do
                begin
                  DBGrid1.SelectedRows.CurrentRowSelected :=True;
                  if CompareBooks(m_TwoBMark,GetBook) =0 then  
                    Exit;
                  Next;
                end;
              end
              else
              begin
                GotoBook(m_TwoBMark);
                while not eof do
                begin
                  DBGrid1.SelectedRows.CurrentRowSelected :=True;
                  if CompareBooks(m_OneBMark,GetBook) =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.GetBook;
              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
                  GotoBook(m_OneBMark);
                  while not eof do
                  begin
                    DBGrid1.SelectedRows.CurrentRowSelected :=True;
                    if CompareBooks(m_TwoBMark,GetBook) =0 then  
                      Exit;
                    Next;
                  end;
                end
                else
                begin
                  GotoBook(m_TwoBMark);
                  while not eof do
                  begin
                    DBGrid1.SelectedRows.CurrentRowSelected :=True;
                    if CompareBooks(m_OneBMark,GetBook) =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.
    仔细看一下上面这个单元,里面就有写