TValueListEditor的使用

今天研究了一下TValueListEditor控件,实现了以下功能:
·按回车键后,自动切换到下一行
·检测输入的值是否为浮点数,如果不是则弹出错误提示
·只允许输入0..9、负号、退格键。

详细功能还是看代码吧.....

 

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids, ValEdit;

type
TForm1
= class(TForm)
lst1: TValueListEditor;
btn1: TButton;
mmo1: TMemo;
btn2: TButton;
procedure btn1Click(Sender: TObject);
procedure lst1KeyPress(Sender: TObject; var Key: Char);
procedure lst1Validate(Sender: TObject; ACol, ARow: Integer; const KeyName,
KeyValue:
string);
procedure btn2Click(Sender: TObject);

private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

//-----------------------------------------------------------
//将输入的值在memo中显示
//-----------------------------------------------------------

procedure TForm1.btn2Click(Sender: TObject);
var
i:Integer;
bb:Extended;
begin
for I := 1 to lst1.RowCount - 1 do
begin
bb :
= StrToFloat(lst1.Cells[2,i]);
mmo1.Lines.Add(FloatToStr(bb));
end;
end;

//-----------------------------------------------------------
//插入一行。
//-----------------------------------------------------------
procedure TForm1.btn1Click(Sender: TObject);
begin
lst1.InsertRow(
'B1','AAA',True);

end;

//-----------------------------------------------------------
//按键处理:
//1.当回车键按下,向下转换焦点,当到达最后一个焦点后,转移到
// 第一个。
//2.输入值只能为数值。
//-----------------------------------------------------------

procedure TForm1.lst1KeyPress(Sender: TObject; var Key: Char);
begin
if Key = #13 then
begin
//ShowMessageFmt('当前行:%d,共有%d行。',[lst1.Row,lst1.RowCount]);
if lst1.Row = (lst1.RowCount -1) then
keybd_event(VK_PRIOR,
0,0,0)
else
keybd_event(VK_DOWN,
0,0,0);
end

else if not (Key in ['0'..'9','.','-',#13,#8]) then
begin
Key :
= #0;
MessageBeep(
1);
end;

end;

//-----------------------------------------------------------
//输入的数值判断:
//1.如果输入的值不能转换为浮点数,则弹出错误提示,同时,
// 光标定位到错误的那一行。
//-----------------------------------------------------------

procedure TForm1.lst1Validate(Sender: TObject; ACol, ARow: Integer;
const KeyName, KeyValue: string);
var
aa:Extended;
begin
//ShowMessageFmt('当前行:%d,当前列:%d,当前值:%s',[arow,acol,keyvalue]);

if not TryStrToFloat(KeyValue,aa) then
begin
ShowMessage(
'Error');
lst1.SetFocus;
lst1.Row :
= ARow;
lst1.Col :
= ACol;
keybd_event(VK_UP,
0,0,0);

end;


end;

end.

转载于:https://www.cnblogs.com/dabiao/archive/2011/09/08/2170432.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值