How to display an empty row when the underlying dataset is empty

本文介绍了一种在Delphi中使用DBTableView时,当数据集查询结果为空时如何显示一条空记录的方法。通过在Grid的OnEnter事件中检查数据集是否为空,并在为空的情况下向数据集中添加一条新记录来实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

    • I have a Grid with a DBTableView. If my dataset query doesn't return anything I would like to show an empty row in my DBTableView (not the NewItemRow, but an empty row). How can I do this?


You can explicitly add a new record to the View's underlying dataset if it's empty. Try to implement the Grid's OnEnter event handler in a similar manner to what is shown below. Hopefully, this will do what you need and it shouldn't be a problem to adapt it.

procedure <Form>.<cxGrid>Enter(Sender: TObject);
var
 View: TcxGridDBTableView;
begin
 View := TcxGridDBTableView((Sender as TcxGrid).FocusedView);
 if View.DataController.DataSet.IsEmpty then
 begin
   View.DataController.DataSet.Append;
   View.Controller.EditingController.ShowEdit;
 end;
end;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值