stringGrid如果涉及到按shift进行多行删除记录的情况,怎么实现?

解决方案 »

  1.   

    有相应的选中属性,好像是selectedindex,然后一行行循环删除即可,记得从下往上删
      

  2.   

    procedure Tf_MG_m.StringGrid1MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);  var i,m,n,m1,m2,n1,n2:integer;
      mgarray:array[0..100]of string;
      begin
      m1:=stringgrid1.selection.left;
      n1:=stringgrid1.Selection.Top;
      m2:=stringgrid1.Selection.Right;
      n2:=stringgrid1.Selection.Bottom;
      i:=0;
            if (m1<>m2) and (n1<>n2) then
            begin
              //for m:=m1 to m2 do
               for n:=n1 to n2 do
                  begin
                      mgarray[i]:=stringgrid1.Cells[0,n];              //memo1.Text:=('m1:'+inttostr(m1)+' n1:'+inttostr(n1)+' m2:'+inttostr(m2)+' n2:'+inttostr(n2));
                      memo1.Text:=memo1.Text+mgarray[i];
                      inc(i);
                    end;
            end;
        end;end.搞成了,自己回了,以上代码是取所删除行的关键字存入一个数组mgarray。之后通过循环对数据库对应表的关键字进行删除操作就行了。stringgrid的数据删除也是获取行坐标进行倒序的删除。(m相当于x轴,n相当于y轴。行标m1到m2相当于x轴的长度,列标n1到n2相当于y轴的长度。也就是坐标(m1,n1)和(m2,n2)是所选矩形的左上角和右下角的坐标)