开发者

How to fill a combobox when a row in a dbgrid is selected?

开发者 https://www.devze.com 2023-02-20 07:41 出处:网络
In Delphi 2007 I have a DBGrid. I need to fill a ComboBox when a row in the DBGrid is selected. The data in the the ComboBox depends on the selected row, and can be different for each selected row.

In Delphi 2007 I have a DBGrid. I need to fill a ComboBox when a row in the DBGrid is selected. The data in the the ComboBox depends on the selected row, and can be different for each selected row.

The DBGrid contains products orders. When an order is selected, I need a ComboBox to be filled with batch numbers of the product in the order. This batch number is saved in the order record, w开发者_如何学Gohen the order is executed.

I could not find a onSelect or onChange event, which I could use to do this.

So how can I do this?


You should use TDataSet.AfterScroll event


If the data comes from a DataSet in a DataModule, as it looks from comments to @Roman response, you can rely on TDataSource events.

If your datasource is also located in the datamodule, you can place a new DataSource in the form itself (IMO is where it belongs).

Then, use the TDataSource.OnDataChange event, from help:

Write an OnDataChange event handler to take specific actions when a field in the current record has been edited and the application moves to another field, or when the current record in the associated dataset changes. OnDataChange is especially useful in applications that must synchronize data display in controls that are not data-aware. This event is typically used to make sure the control reflects the current field values in the dataset, because it is triggered by all changes.

The Field parameter is nil when the linked dataset is moving to a new record or refreshing a record buffer. The Field is not nil when the changes belong to a particular field (a user or the program itself changing it's value).


I suggest the double click event (OnDblClick) to catch when the user clicks with his mouse and OnKeyPress for the Enter key (Key=#13)

0

精彩评论

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

关注公众号