【例子介绍】dbgrideh实现下拉列表
【相关图片】
【源码结构】
unit Unit1; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, DBGridEhGrouping, ToolCtrlsEh, DBGridEhToolCtrls, DynVarsEh, Data.DB, Data.Win.ADODB, EhLibVCL, GridsEh, DBAxisGridsEh, DBGridEh, Datasnap.DBClient; type TForm1 = class(TForm) grd1 :TDBGridEh; ds1 :TDataSource; cds1 :TClientDataSet; cds1Goods :TStringField; cds1Qutity :TIntegerField; qry1 :TADOQuery; procedure FormCreate(Sender :TObject); procedure grd1Columns0UpdateData(Sender: TObject; var Text: string; var Value: Variant; var UseText, Handled: Boolean); private c: TColumnEh; { Private declarations } public { Public declarations } end; var Form1 :TForm1; implementation uses MidasLib; {$R *.dfm} procedure TForm1.FormCreate(Sender :TObject); begin cds1.CreateDataSet; c := grd1.Columns[0]; qry1.Open; qry1.First; while qry1.Eof = False do begin c.PickList.Add(qry1.FieldByName('goods').AsString); qry1.Next; end; end; procedure TForm1.grd1Columns0UpdateData(Sender: TObject; var Text: string; var Value: Variant; var UseText, Handled: Boolean); begin if c.PickList.IndexOf(Text)=-1 then c.PickList.Add(Text); end; end.
评论