设置DbgridEh选择多行,并操作选中行

var
  i:Integer;
begin
//Edit1.Text:=IntToStr(DBGridEh1.SelectedRows.Count);
if DBGridEh1.SelectedRows.Count>0 then
begin
for i:=0 to DBGridEh1.SelectedRows.Count-1 do
   begin
   qryBLOB.GotoBookmark(pointer(DBGridEh1.SelectedRows.Items[i]));
   qryBLOB.Edit;
   qryBLOB.FieldByName('code').AsString:=Edit1.Text;
   qryBLOB.Post;
   end;
   
end;
end;








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

你可能感兴趣的:(Delphi)