procedure TForm1.Button1Click(Sender: TObject); var i, j: Integer; s: string; begin if DBGrid1.SelectedRows.Count>0 then with DBGrid1.DataSource.DataSet do for i:=0 to DBGrid1.SelectedRows.Count-1 do begin GotoBook(pointer(DBGrid1.SelectedRows.Items[i]));//选中的记录 //……做你的事 end; end;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if( gdSelected in State)then BEGIN
DBGRID1.Canvas.Brush.Color := CLRED;
DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, [gdSelected]);
END;
end;
注意设置options中的dgRowSelected为True;,dgMultiSelect为True,defaultDrawing为False
if( gdSelected in State) then
var
i, j: Integer;
s: string;
begin
if DBGrid1.SelectedRows.Count>0 then
with DBGrid1.DataSource.DataSet do
for i:=0 to DBGrid1.SelectedRows.Count-1 do
begin
GotoBook(pointer(DBGrid1.SelectedRows.Items[i]));//选中的记录
//……做你的事
end;
end;
//……做你的事
我写为:
adotable1.FieldByName('taxrate').AsString:='2';
adotable1.Post; 但运行出错:(我用adotable,adoconnection,datasource连接的数据库为:access数据库dbdemos中的customer表)
adoTable1.Edit;//加上这句,因为在gotoBookMark后状态已变为Brows
adotable1.FieldByName('taxrate').AsString:='2';
adotable1.Post;