用下面这段就可以了,不用以前的这么麻烦
procedure TForm1.StringGrid1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if key=VK_LEFT then begin
with stringgrid1 do
if col > 0 then
col := col - 1;
end;
if key=VK_RIGHT then begin
with stringgrid1 do
if col < colcount then
col := col + 1;
end;
end;
procedure TForm1.StringGrid1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if key=VK_LEFT then begin
with stringgrid1 do
if col > 0 then
col := col - 1;
end;
if key=VK_RIGHT then begin
with stringgrid1 do
if col < colcount then
col := col + 1;
end;
end;
解决方案 »
- IDE如何获取其对象的属性,变量,函数和过程
- 根据数字键盘查询stringgrid中相对应的内容?
- LB控件为什么在我的系统上没法注册
- 怎样判断当前是否连在Internet上?
- 如何读出大于32K的数据流(jpg)?
- 我用DELPHI6来连接ACCESS时那个密码的问题处理不好
- [讨论]:关于DELPHI中ADO缓存更新技术的并发处理
- 关于屏闭del+alt+ctrl的问题?
- 请问用delphi里面能不能创建控件数组呀!
- 简单之极!快来枪分!请问如何在Form找到当前得到焦点的控件?
- 如何用delphi实现用SQL语句动态的创建表?
- TQuery的sql语句用select语句,想看返回了有多少行,用那个参数??
你没理解我的问题所在
我的问题是。 比如一个CELLS的值是'abcdefg',
光标是在d和e 中间,我如何知道光标的位置。因为我想实现一个
功能是,比如当用户在对某一个CELLS中的值进行编辑,CELLS的值是'abcdefg',
而光标是在d和e之间,如果用户使用左移键,那么在STRINGGRID的缺省情况下
,光标是从d和e之间移动到c和d 之间, 问题是在当光标已经处于a之前,如果用户再使用左移键,那么我希望光标是
移动到前一个CELLS,也就是你说的COL + 1,
我的问题就是怎么判断光标已经位于当前CELLS的值的最前端了,当用户使用左移键,
然后我就可以通过COL + 1 实现了。??谢谢
谢谢
procedure TForm1.StringGrid1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
var
cc:TInplaceEdit;
begin
if stringgrid1.EditorMode then begin
cc:=stringgrid1.controls[0] as TInplaceEdit;
if (key=VK_LEFT) and (cc.SelStart=cc.sellength) then begin
stringgrid1.EditorMode:=false;
PostMessage(StringGrid1.Handle,WM_KEYDOWN,Key,0);
PostMessage(StringGrid1.Handle,WM_KEYUP,Key,0);
end
else
if (key=VK_RIGHT) and (cc.SelStart=length(cc.Text)) then begin
stringgrid1.EditorMode:=false;
PostMessage(StringGrid1.Handle,WM_KEYDOWN,Key,0);
PostMessage(StringGrid1.Handle,WM_KEYUP,Key,0);
end;
end;
end;
这回我应该没有看错吧:)
果然是高手,分数送上了,谢谢你的帮助,