我研究的初步结果
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, Grids, DBGrids;
type
TForm1 = class(TForm)
DBGrid1: TDBGrid;
DataSource1: TDataSource;
ADOTable1: TADOTable;
ADOConnection1: TADOConnection;
procedure DBGrid1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure ADOTable1BeforeScroll(DataSet: TDataSet);
procedure DBGrid1KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
private
{ Private declarations }
F:Boolean;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.DBGrid1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
with dbgrid1, dbgrid1.SelectedRows do
begin
if (CurrentRowSelected = true)
and (DataSource.Dataset.FieldValues['name'] = '烙铁') //询问条件
and (MessageDlg('你是否选择“烙铁”?', mtConfirmation, [mbYes, mbNo], 0) = mrNo) //询问过程
then
CurrentRowSelected := False;
end;
end;
procedure TForm1.DBGrid1KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
with dbgrid1, dbgrid1.SelectedRows do
begin
if (F = true)
and (DataSource.Dataset.FieldValues['name'] = '烙铁') //询问条件
and (MessageDlg('你是否选择“烙铁”?', mtConfirmation, [mbYes, mbNo], 0) = mrNo) //询问过程
then
CurrentRowSelected :=false;
end;
end;
procedure TForm1.ADOTable1BeforeScroll(DataSet: TDataSet);
begin
F:=dbgrid1.SelectedRows.CurrentRowSelected;
end;
end.