光标离开单元格就提交数据到ClientDataSet.Delta

procedure TfrmdbxError.DBGrid1ColExit(Sender: TObject);
begin
  if dmHandleError.cdsAuthors.State = dsEdit then
    dmHandleError.cdsAuthors.Post;

end;


可能不用写这个了;因为这个事界面上的,不是数据变化上的,这样写不和逻辑;在cds.fields[i].OnChange里面post也可以

在Delphi中,可以使用TListView组件结合TAdapterBindSource和TAdapterListViewAdapter来将Access表中的数据适配到ListView上显示。下面是一个示例代码,展示如何实现这个功能: ```delphi unit MainForm; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Data.Bind.GenData, Data.Bind.EngExt, Vcl.Bind.DBEngExt, System.Rtti, System.Bindings.Outputs, Vcl.Bind.Editors, Data.Bind.Components, Data.Bind.Grid, Vcl.Grids, Data.Bind.ObjectScope, Vcl.StdCtrls, Vcl.ExtCtrls, Vcl.Bind.Navigator, Vcl.ComCtrls; type TForm1 = class(TForm) ListView1: TListView; Button1: TButton; procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); private FPersonList: TObjectList<TPerson>; procedure LoadData; public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} uses System.Generics.Collections, Data.DB, Datasnap.DBClient; type TPerson = class FirstName: string; LastName: string; Age: Integer; end; procedure TForm1.FormCreate(Sender: TObject); begin FPersonList := TObjectList<TPerson>.Create; end; procedure TForm1.Button1Click(Sender: TObject); var ClientDataSet: TClientDataSet; begin LoadData; ClientDataSet := TClientDataSet.Create(Self); try // 将Access表中的数据加载到ClientDataSet中 // 这里假设Access表中包含字段FirstName、LastName和Age // 可根据实际情况进行修改 ClientDataSet.FieldDefs.Add('FirstName', ftString, 50); ClientDataSet.FieldDefs.Add('LastName', ftString, 50); ClientDataSet.FieldDefs.Add('Age', ftInteger); ClientDataSet.CreateDataSet; for Person in FPersonList do begin ClientDataSet.Append; ClientDataSet.FieldByName('FirstName').AsString := Person.FirstName; ClientDataSet.FieldByName('LastName').AsString := Person.LastName; ClientDataSet.FieldByName('Age').AsInteger := Person.Age; ClientDataSet.Post; end; ListView1.Items.Clear; ListView1.ItemAppearanceObjects.ItemObjects.Text.Text := 'FirstName'; ListView1.ItemAppearanceObjects.ItemObjects.Detail.Text := 'LastName'; ListView1.ItemAppearanceObjects.ItemObjects.Accessory.Text := 'Age'; // 将ClientDataSet绑定到ListView上 ListView1.Adapter := TListBindSourceAdapter.Create(Self, ClientDataSet); finally ClientDataSet.Free; end; end; procedure TForm1.LoadData; var Person: TPerson; begin Person := TPerson.Create; Person.FirstName := 'John'; Person.LastName := 'Doe'; Person.Age := 25; FPersonList.Add(Person); Person := TPerson.Create; Person.FirstName := 'Jane'; Person.LastName := 'Smith'; Person.Age := 30; FPersonList.Add(Person); end; end. ``` 在上述代码中,首先在FormCreate事件中创建了一个TObjectList<TPerson>对象,用于存储要显示的数据。在Button1Click事件中,通过LoadData方法加载数据,并将数据适配到一个TClientDataSet对象中。 然后,将TClientDataSet对象的字段定义为与Access表中的字段相匹配,并将数据逐条添加到TClientDataSet中。 接下来,通过TListBindSourceAdapter类将TClientDataSet对象绑定到ListView的Adapter属性上,实现数据的绑定和显示。 请注意,在使用TAdapterBindSource和TAdapterListViewAdapter时,需要在uses中添加Data.DB和Datasnap.DBClient单元,并在项目中引用DataSnap和DBClient相关包文件。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值