Link to home
Start Free TrialLog in
Avatar of Donoss
DonossFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Delphi 2007 - RzDBGrid.SelectedRows.CurrentRowSelected

Hi,

I'm using D2007, Vista Business and Raize 4.3.1.

I'm using the following code to delete dataset records from a a RzDBGrid (Note: DMod.pFIBDataSetNotRAPermit contains the items not in the dataset):

procedure TFrmRA.RzBitBtn2Click(Sender: TObject);
begin
  RzDBGrid3.SelectedRows.Delete;
  DMod.pFIBDataSetNotRAPermit.CloseOpen(True);
end;

All works Fine.

However I'm using the following to add items to a grid:

procedure TFrmRA.RzBitBtn1Click(Sender: TObject);
begin
  DMod.pFIBDataSetNotRAPermit.First;
  while not DMod.pFIBDataSetNotRAPermit.eof do begin
    if RzDBGrid6.SelectedRows.CurrentRowSelected then begin
      DMod.pFIBDataSetRAPermit.Insert;
      DMod.pFIBDataSetRAPermitPERMIT_DESCRIPTION.Text := RzDBGrid6.SelectedField.AsString;
      DMod.pFIBDataSetRAPermit.Post;
    end;
    DMod.pFIBDataSetNotRAPermit.Next;
  end;
  DMod.pFIBDataSetNotRAPermit.CloseOpen(True);
end;

The first time I add a record it adds the selected item(s) and always adds the first item in the dataset, even when not selected.  If I try to add additional records then only the selected items are added, the problem is only when adding the first item!!!!

Can anyone please help?

Many thanks

Andy
Avatar of dinilud
dinilud
Flag of India image

Give the dataset properties of Grids.
Avatar of carcotasu
carcotasu

It is not suficient cu go next of the record, you must select then new row. look in the properties of the Grids maybe have property to select a row from code, something like this: RzDBGrid6.SelectedRows:= recno of table.
Avatar of Donoss

ASKER

Dinilud,

I'm not sure what you are saying here, can you please expand on your explanation?

ASKER CERTIFIED SOLUTION
Avatar of dinilud
dinilud
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Donoss

ASKER

Guy's I've split the points for your help.  My code above does in fact work fine, the problem was I had the wrong master datasource set for DMod.pFIBDataSetNotRAPermit, it should have been DataSetRA not DataSetRAPermit, therefore when I'm doing the insert it was resetting DMod.pFIBDataSetNotRAPermit to the first record and copying this in.

Thanks again
Avatar of Donoss

ASKER

Guy's I've split the points for your help.  My code above does in fact work fine, the problem was I had the wrong master datasource set for DMod.pFIBDataSetNotRAPermit, it should have been DataSetRA not DataSetRAPermit, therefore when I'm doing the insert it was resetting DMod.pFIBDataSetNotRAPermit to the first record and copying this in.

Thanks again