开发者

Delphi - Update field in a dbGrid while selection is on another row

I got a dbGrid with X rows. I want to update a field-value in the second row with a timer (for example, show a countdown). Thats no problem, but I want to be able to change the selected row and keep updating the second row. When the selection changes in the grid, the current record of the connected dataset changes as well, and thats a problem because the code in the timer points to the selected record.

How could that be开发者_开发技巧 solved? Thanks!


If dataset connected to dbGrid is TClientDataSet, you can drop another TClientDataSet and clone data from grid's dataset.

Since both datasets will point to same data, you can change values in cloned dataset, and that data will show in dbGrid without tampering with dbGrids dataset.


Try this very straightforward approach:

if DataSource1.DataSet.State in dsEditModes then
  DataSource1.DataSet.Post; { or Cancel, depends on your needs }
try
  DataSource1.DisableControls;
  Bookmark := ClientDataSet1.GetBookmark;
  try
    if ClientDataSet1.Locate(SecondRowId, 'Id', []) then
    begin
      ClientDataSet1.Edit;
      ClientDataSet1['Counter'] := Counter;
      ClientDataSet1.Post;
    end;
    ClientDataSet1.GotoBookmark(Bookmark);
  finally
    CLientDataSet1.FreeBookmark(Bookmark);
  end;
finally
  DataSource1.EnableControls;
end;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜