Select row after DBGrid update

Well, some question n00b from me. I dealt with the network and other similar questions, but did not find the correct answers for such a simple (as I thought) problem.

I have a DBGrid. I select one row and do some actions with other data associated with this row. After I finished, my DBGrid is updated and the selected row is first reset. I want the selected selected row to be selected before updating the DBGrid data. Any suggestions?

+5
source share
3 answers

Before upgrading, save the currently selected dataset as a bookmark, then restore the bookmark later.

+4

, . , , RecNo . TDataSet RecNo . , . 0 RecNo , .

procedure TMyForm.DoSomethingWithDataSet(ADataSet : TDataSet);
var
  Bookmark : TBookmark;
begin
  Bookmark := ADataSet.GetBookmark; // Save your place in ADataSet

  try
    Screen.Cursor := crSqlWait;  // Show the user that something is happening
    Update;  // update the form to make sure screen cursor updates
    ADataSet.DisableControls;
    // do something with ADataSet here  e.g.
    ADataSet.First;
    while not ADataSet.Eof do begin
      // do something with current row here, then
      ADataSet.Next;
    end;
  finally
    ADataSet.GotoBookmark(Bookmark);  // Return to where you were at outset
    ADataSet.FreeBookmark(Bookmark);
    ADataSet.EnableControls;
    Screen.Cursor := crDefault;  // Let the user see you're done
  end;
end;
+4
RecKey:=DmFRM.ViewTBL.RecNo;
          with DmFRM.ViewTBL do
               begin
                  Active:=false;
                  Active:=True;
                  RecNo:=RecKey;
               end;
-1
source

All Articles