如何在DBGrid的每一行前加一个单选框

StyleControls VCL 5.87 源码解析:老项目 UI 换肤与编译实践 Delphi 开发者在维护 VCL 桌面应用时,经常面临界面观感老旧、迁移 FMX 成本高等困境。控件级换肤作为一种轻量改造思路,通过重写控件绘制逻辑,可以在不改变框架的前提下实现现代 UI 效果。StyleControls 作为 VCL 生态中一套完整的原生控件库,覆盖按钮、编辑框、面板、列表等常见组件,同时提供全局样式桥接与 DPI、字体适配能力,适合用于老系统界面升级。本文围绕 StyleControls VCL 5.87 FullSource 完整源码版,梳理了包体编译顺序、核心控件使用、渐进式改造 阅读详情
 

如何在DBGrid的每一行前加一个单选框?


Unit Unit1;

Interface

Uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids, DBGrids, DB, ADODB;

Type
  TForm1 = Class(TForm)
    DataSource1: TDataSource;
    ADOTable1: TADOTable;
    DBGrid1: TDBGrid;
    Procedure DBGrid1DrawColumnCell(Sender: TObject; Const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);
    Procedure DBGrid1ColEnter(Sender: TObject);
    Procedure DBGrid1ColExit(Sender: TObject);
    Procedure DBGrid1CellClick(Column: TColumn);
    Procedure DBGrid1KeyDown(Sender: TObject; Var Key: Word;
      Shift: TShiftState);
  private
    OriginalOptions: TDBGridOptions;
    Procedure SaveBoolean;
    { Private declarations }
  public
    { Public declarations }
  End;

Var
  Form1: TForm1;

Implementation

{$R *.dfm}

Procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; Const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
Const // 这个整数值将按照布尔值返回,并送入数组
  CtrlState: Array[Boolean] Of Integer = (DFCS_BUTTONCHECK, DFCS_BUTTONCHECK Or DFCS_CHECKED);
 // CtrlString:=string;
Begin
//确保只有在逻辑字段才能插入组件
  If Column.Field.DataType = ftBoolean Then
  Begin
    DBGrid1.Canvas.FillRect(Rect);
    DrawFrameControl(DBGrid1.Canvas.Handle, Rect, DFC_BUTTON, CtrlState[Column.Field.AsBoolean]); //画框框
   // Column.Field.Text:='google';

  End;
End;

Procedure TForm1.DBGrid1ColEnter(Sender: TObject);
Begin
// 确保该栏是逻辑字段
  If DBGrid1.SelectedField.DataType = ftBoolean Then
  Begin
    OriginalOptions := DBGrid1.Options;
    DBGrid1.Options := DBGrid1.Options - [dgEditing];
  End;
End;

Procedure TForm1.DBGrid1ColExit(Sender: TObject);
Begin
//确保该栏是逻辑字段
  If DBGrid1.SelectedField.DataType = ftBoolean Then
    DBGrid1.Options := OriginalOptions;
End;

Procedure TForm1.DBGrid1CellClick(Column: TColumn);
Begin
//确保该栏是逻辑字段
  If DBGrid1.SelectedField.DataType = ftBoolean Then
    SaveBoolean();
End;

Procedure TForm1.DBGrid1KeyDown(Sender: TObject; Var Key: Word;
  Shift: TShiftState);
Begin
//确保该栏是逻辑字段和空格键在键盘中被敲击
  If (Key = VK_SPACE) And (DBGrid1.SelectedField.DataType = ftBoolean) Then
    SaveBoolean();
End;

Procedure TForm1.SaveBoolean;
Begin
  DBGrid1.SelectedField.Dataset.Edit;
  DBGrid1.SelectedField.AsBoolean := Not DBGrid1.SelectedField.AsBoolean;
  DBGrid1.SelectedField.Dataset.Post;
End;
End.

实现dbgrid中添加checkbox 在dbgrid中实现checkbox,同时附带的实现formdate的使用,和datetime的使用。仅仅是一个小例子 立即下载

相关推荐

dbgridEh,列中可以有复选框

dbgridEh是增强的dbgrid版本,在字段中可以有复选框。

如何在DBGrid的每一行前加一个单选框?

Unit Unit1;InterfaceUses  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,  Dialogs, Grids, DBGrids, DB, ADODB;Type  TForm1 = Class(TForm)    DataSource1: TDataSource; 

潇湘博客 3785

SECS/GEM协议中的关键指令详解:从S1F1到S9F9的完整指南

本文详细解析了SECS/GEM协议中从S1F1到S9F9的关键指令,涵盖设备状态管理、控制诊断、报警处理等核心功能。通过实际案例和调试技巧,帮助开发者掌握半导体制造设备通信标准,解决SECS/GEM协议在实际工程应用中的通讯难题,提升生产线智能化水平。

weixin_26899659的博客 410

dbgrideh 加入checkbox选择框

1,在adoquery 或者fdquery 加入一个加个字段byte类型type为internalCalc 2,

全粘工程师 1436

双目立体成像(一)双目图片生成点云

利用左右目图片生成点云

qq_62964142的博客 4558

通过 CoovaChilli 和 FreeRADIUS 搭建一个公共 Wi-Fi 的认证系统,实现用户连接到 Wi-Fi 后通过 Captive Portal(强制登录页面)进行认证

要实现固定设备连接的功能,你可以通过MAC 地址认证来限制哪些设备可以通过 FreeRADIUS 进行身份验证和连接。你可以在 FreeRADIUS 的users文件中直接配置允许的设备的 MAC 地址,也可以通过数据库存储和查询设备信息,进一步提高管理效率。通过这些方法,你可以灵活地控制哪些设备能够访问你的 Wi-Fi 网络。

m0_69943017的博客 2660

Delphi实现DBGridEh复选框

一、数据库中增加一个字段 给数据库中增加一个字段(sqlserver:bit类型,oracle:char(1)类型),值为0或1。 DBGridEh表格中列属性CheckBoxes设置为True,将KeyList设置为0和1.。 设置完成,点击复选框,即可选中与取消选择,同时数据库中的该字段值也对应改变。 设置DBGridEh表格中的OnTitleClick函数,点击表头,实现全选与全消。 具体实现: 增加字段 设置复选框 设置KeyList 点击单元格选择 数据库同步字段值修改 全选 全消

solo_1108的博客 3977

智能排班考勤系统原型

可实现从业务预测,到工时预估,再到人员分配全流程自动智能排班。可应用于客服行业或工厂的智能排班系统。

gywm15111336483的专栏 999

为DataGrid列添加Radio(单选框)列

经常看到论坛上有人问在DataGrid中如何实现单选,下面就是一种实现的方法。查看例子<%@ Page Language="C#" AutoEventWireup="True" EnableViewState = "true"%><%@ Import Namespace="System.Data&q

doublewang的专栏 1496

节卡Jaka Zu APP编程避坑指南:从频繁通讯错误到稳定Socket交互的调试心得

本文详细解析了节卡Jaka Zu APP编程中常见的通讯错误问题,并提供了从基础排查到高级调试的完整解决方案。通过优化网络配置、固件匹配、心跳机制和数据交互规范,开发者可实现稳定的Socket通讯,有效提升工业机器人操控的可靠性。文章特别针对v1.6.7.3版本的典型问题给出了实用调试技巧。

weixin_42639633的博客 329

最优控制 (Optimal Control) 算法详解及案例分析

最优控制是一种通过优化控制输入,使系统在满足约束条件的情况下达到最优性能的控制方法。其目标是最小化或最大化一个性能指标。

闲人编程的博客 2100

通用DbGrid的设计与实现

     以 前做计费软件或其他Web开发时,经常碰到各种表格,而百分之七八十的表格操作都是简单的增,删,改,为了提供开发效率,特开发DbGrid控件,以加快表格开发速度以及公用。          针 对目前我们WEB系统开发过程中需要用到大量列表,而对列表的灵活的操作成为重中之重,比如更改列表中局部数据用来保存,列表可以灵活出现提示信息,列表可以支持针对某条记录的右键操作,列表可以进行排序,...

118

YOLO26涨点改进 | Conv篇/小目标改进 | AAAI 2025 FBRT-YOLO 两个轻量级FCM和MKP模块, 助力无人机航拍任务VisDrone、UAVDT和AI-TOD高效涨点

本文提出FBRT-YOLO26模型,通过引入两个轻量级模块FCM和MKP优化航拍图像检测性能。FCM模块通过特征互补映射解决小目标信息丢失问题,MKP模块利用多尺度卷积核增强目标感知能力。在VisDrone等数据集上的实验表明,该方法在精度和速度上均优于现有实时检测器。文章详细介绍了模块结构、核心代码实现及YAML配置文件修改方法,为航拍图像中的小目标检测提供了高效解决方案。该模型实现了检测精度与效率的良好平衡,具有实际应用价值。

Ai缝合怪、助力小伙伴高效发论文 376

vb data绑定控件简介

Grid控件:Grid控件可显示简单的二维表格,不用和数据库直接连接,具有滚动条、行头、列头等特性,运行时可用鼠标调整行列的宽度,可用于浏览数据,若想对数据进行编辑,需结合TextBox控件,或采取其他变通方法。Grid只是提供了一个预览的功能,便于数据的修改。由Grid的特点及其使用方法可以看出,在需要对数据库进行大量数据的操作时,为了减少对数据库的直接操作,提高数据库的安全性,使用Grid控件

也想快乐的生活 3890

YOLOv8n轻量化实战:10分钟打通实时摄像头目标检测,附参数调优与避坑指南

本文介绍了如何快速入门YOLOv8目标检测框架,通过摄像头实战实现实时检测。YOLOv8凭借轻量化架构和跨平台优势,是新手入门的理想选择。文章详细讲解了环境搭建(1分钟完成)、核心代码逻辑(3分钟掌握)以及性能调优技巧(3分钟进阶),提供可直接运行的代码示例。重点包括:模型选择(优先yolov8n.pt)、摄像头参数优化、置信度阈值调整、检测类别指定等实用技巧,帮助开发者快速实现10-15FPS的实时检测效果,并针对不同场景提供优化建议。

专注于Python爬虫开发,分享爬虫技巧、项目实战与反爬经验,使用Scrapy、BeautifulSoup等工具,解决数据抓取难题。 381

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

在TDBGrid中绘制一个多选框(CheckBox)

可在TDBGrid的OnDrawColumnCell和OnDrawDataCell事件中编写void __fastcall TForm1::DBGrid1DrawColumnCell(TObject *Sender, const TRect &Rect, int DataCol, TColumn *Column, TGridDrawState State){ if

Compile failed 3120

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

数据列表组件dbgrids.xml配置说明

数据列表组件dbgrids.xml配置说明 参数 使用说明 grid-name* 标识dbgrid,其为唯一,大小写敏感。调用时以此为参数 grid-table* 列表中数据的来源。如果有多个表,以逗号隔开。如table1 tb1,table2 tb2 其中tb1为table1的别名,tb2为table2的别名。 grid-cols* 列表的数...

weixin_30887919的博客 81

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

我在DBGridEh增加一栏复选框及对应操作的解决方案

最近客户有个需求,要求对单据列表里指定的单据进行批量审核,很自然的,我想到了在DBGridEh增加一栏复选框的列,审核时遍历所有单据,将打了勾的单据审核就可以了。查阅了网上很多文章,不外有2个方案,1是在数据表里增加字段,2是直接在DBGridEh增加一个没有字段的栏,也许是我笨吧,2种方案试过了都不行,于是只能自己想办法了。研究了半天结合前面的2个方案,我想到了一个解决的方法,分享给大家吧。 ...

数据狂的专栏 4286

TDBGrid设置“选择”字段

当数据集有选择的时候,比如选择性打印,而且这种选择是随用户的主观意念决定时。在DBGrid上设置选择项,就非常必要和非常有用了。     在DBGrid上设置选择项,操作如下:     一、加入DB单元,因为要DB相关设置。 uses DB;     二、在Table的字段设置一个可供选择的字段,例使用中文字段“选择”,属性:bit。     三、显示Table的DBGrid中,将该

lyhoo163的专栏 6335

delphi 自带的dbgrid表格控件增加下选框

自带的dbgrid加也很方便,环境是xe10。在表格里用combobox很正常。

全粘工程师 645

dbgrid添加复选框实现多选功能

最近开发的DELPHI项目中,遇到这样的一个常见的需求,DBgrid实现多选功能。这个功能第三方控件其实可以直接拿来用,现在我们在不使用三方控件的情况看看如何实现

weng10252002的专栏 2339

给 DBGridEh 增加勾选用的检查框 CheckBox

如何为 DBGridEh 增加多选的 CheckBox 勾选框

pcplayer的博客 820

Delphi DBGridEH中,选中行、列、单元格

// 新增行后,默认首列 procedure TForm1.ADOQuery1AfterInsert(DataSet: TDataSet); begin   with DBGridEh1 do   begin     SelectedIndex := 0;   end; end; // 行选中 DBGridEh_Yingfu_SearchQK.SelectedRows.S

gjtao1130的专栏 1万+
上一篇: Delphi 函数和过程的参数问题
下一篇: Delphi--异常和错误处理
hhhfff2010
博客等级 码龄17年 26粉丝 10原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值