怎样通过pop菜单删掉dbgrid里选中的多行记录,并在数据库中把关联的所有数据删掉??
主要是通过pop菜单怎样知道要删的记录ID?

解决方案 »

  1.   

    思路错了,不是通过Pop菜单知道,而是通过OnMouseDown事件知道,而且Pop菜单也是在这个事件里面显示弹出,参考:procedure TForm1.StringGrid1MouseDown(Sender: TObject;
      Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    var
      Point: TPoint;
    begin
      if mbLeft = Button then Exit;
      Point.X:=X;
      Point.Y:=Y;
      Point:=ClientToScreen(Point);
      PopupMenu1.Popup(StringGrid1.Left+Point.X, StringGrid1.Top+Point.Y);
    end;
      

  2.   

    for i:=0 to dbgrid1.SelectedRows.count-1 do
    begin
      GotoBook(pointer(dbgrid1.SelectedRows.items[i])); //定位选中的记录
      showmessage(dbgrid1.datasource.dataset.fields[0].asstring);
    end;
      

  3.   

    sorry,更正
    for i:=0 to dbgrid1.SelectedRows.count-1 do
    begin
    dbgrid1.datasource.dataset.GotoBook(pointer(dbgrid1.SelectedRows.items[i])); //定位选中的记录
    showmessage(dbgrid1.datasource.dataset.fields[0].asstring);
    end;