1. 将DbgridEh的Option里面的dgRowSelect和dgMultiSelect设为true,即可按住ctrl选择多行,但是这样的话不允许修改单元格
2. 如果要在“允许选择多行”和“允许修改单元格”两种状态之间切换,可使用如下代码:
//允许选择多行但不允许修改单元格
DBGridDetail.Options :=[gTitles,dgIndicator,dgColumnResize,dgColLines,dgRowLines,dgTabs,dgRowSelect,dgConfirmDelete,dgCancelOnExit,dgMultiSelect];
//允许修改单元格但不允许选择多行
DBGridDetail.Options :=[gTitles,dgIndicator,dgEditing,dgColumnResize,dgColLines,dgRowLines,dgTabs,dgConfirmDelete,dgCancelOnExit];
3. 选择多行时,操作所选择的行
with ADOQryDetail do
for i:=0 to (DBGridDetail.SelectedRows.Count - 1) do
begin
GotoBookmark(pointer(DBGridDetail.SelectedRows.Items[i])); //关键是这一句
with frmwage_detail_mod.ADOQryDetail do
begin
First;
while not Eof do
begin
frmwage_detail.ADOQryDetail.Edit;
frmwage_detail.ADOQryDetail.FieldByName(FieldByName('N_DATE_TYPE_D').AsString).AsString
:= FieldByName('N_REMARK').AsString;
Next;
end; //while
end; //with
end; //for