太简单了 if adoquery.eof and adoquery.bof then exit; //具有记录显示当前记录 edit1.text:=adoquery.fieldvalues['aa']; ........
adoQuery1.FieldByName('ColName').AsString;
if adoquery.stae=dsEdit then adoquery.post; edit1.text:=adoQuery1.FieldByName('ColName').AsYourType; edit2.... ..... adoQuery1.Edit; 这就是在浏览事件里
但如何知道dbgrid当前有没有记录被选中呢(必须显示当前选择的记录)
var x: word; TempBook: TBookMark; begin DBGrid1.Datasource.Dataset.DisableControls; if DBgrid1.SelectedRows.Count <> 0 then begin TempBook:= DBGrid1.Datasource.Dataset.GetBook; for x:= 0 to DBgrid1.SelectedRows.Count - 1 do begin if DBgrid1.SelectedRows.IndexOf(DBgrid1.SelectedRows.Items[x]) > -1 then begin DBGrid1.Datasource.Dataset.Book:= DBgrid1.SelectedRowsItems[x]; showmessage(DBGrid1.Datasource.Dataset.Fields[1].AsString); end; end; end; DBGrid1.Datasource.Dataset.GotoBook(TempBook); DBGrid1.Datasource.Dataset.FreeBook(TempBook); DBGrid1.Datasource.Dataset.EnableControls; end;
to Tiga(我要学习) :我设置dgRowSelect=true;dgMultiSelect=false;使dbgrid只能同时选中一行,所以DBgrid1.SelectedRows.Count为0;因为必须 设置dgRowSelect=true;dgMultiSelect=true;之后SelectedRows才有意义
if adoquery.eof and adoquery.bof then exit;
//具有记录显示当前记录
edit1.text:=adoquery.fieldvalues['aa'];
........
edit1.text:=adoQuery1.FieldByName('ColName').AsYourType;
edit2....
.....
adoQuery1.Edit;
这就是在浏览事件里
var
x: word;
TempBook: TBookMark;
begin
DBGrid1.Datasource.Dataset.DisableControls;
if DBgrid1.SelectedRows.Count <> 0 then
begin
TempBook:= DBGrid1.Datasource.Dataset.GetBook;
for x:= 0 to DBgrid1.SelectedRows.Count - 1 do
begin
if DBgrid1.SelectedRows.IndexOf(DBgrid1.SelectedRows.Items[x]) > -1 then
begin
DBGrid1.Datasource.Dataset.Book:= DBgrid1.SelectedRowsItems[x];
showmessage(DBGrid1.Datasource.Dataset.Fields[1].AsString);
end;
end;
end;
DBGrid1.Datasource.Dataset.GotoBook(TempBook);
DBGrid1.Datasource.Dataset.FreeBook(TempBook);
DBGrid1.Datasource.Dataset.EnableControls;
end;
设置dgRowSelect=true;dgMultiSelect=true;之后SelectedRows才有意义