What event fires every time a selected TDbGrid location changes?

I have TDbGrid in my project and I try to delete the event every time I change the selected row. Any change in the row already updates all controls associated with the data associated with the same data source, but there are other changes that I need to handle events.

I thought OnColEnter would work. According to the help file, it fires when:

  • The user navigates to the cell using the keyboard. For example, when the user uses the Tab key or the Home key.

  • The user presses the mouse button down in the cell.

  • The SelectedField or SelectedIndex property is set.

Unfortunately, it does not work when the user navigates using the keyboard, and the dgRowSelect option is enabled, and there is no OnRowEnter. And the OnKeyDown event fires before the selection change has been made. I am trying to mimic a version of TListBox that supports data, and I need to replace something with the OnClick List Box handler, which, despite the fact that the name is really disabled at any time when the selection changes, whether using the mouse or keyboard. Is there a way to do this using TDbGrid? If not, there must be some other grid control that will do this. Does anyone know what this is? (Preferably open source?)

+3
source share
4 answers

OnDataChange - . - TDataset - AfterScroll. , OnDataChange; OnDataChange Field nil ( AV-).

+3

OnDataChange DataSource?

+8

OnDataChange , , false, .

procedure TForm1.DataSource1DataChange(Sender: TObject; Field: TField);
begin
  if fbLoading then exit;
  // rest of your code here
end;

procedure TForm1.Form1Create(Sender:tObject);
begin
  fbLoading := true;
  // load your table here     
  fbLoading := false; 
end;
+2

I would use AfterScroll only in the data set, it starts when you first open the data set, and every time you move in it. In DBGrid, which will be on every click on a row or scroll bar, or using the keyboard (Home, Edn, Up, Down, PgUp, PgDown) ... etc.

You can even dynamically assign it if you use the same dataset in many different forms (either in Create / Free or Show / Close):

procedure TForm1.myAfterScroll(DataSet: TDataSet); 
begin
   //do your thing here
   if oldAfterScroll<>nil then
      oldAfterScroll(DataSet);
end;

constructor TForm1.Create(AOwner: TComponent);
begin
   oldAfterScroll:=DBGrid1.DataSet.OnAfterScroll;
   DBGrid1.DataSet.OnAfterScroll:=myAdrerScroll;
end;

destructor TForm1.Free;
begin
   DBGrid1.DataSet.OnAfterScroll:=oldAfterScroll;
end;
+1
source

Source: https://habr.com/ru/post/1699642/


All Articles