TSTRINGRID 的ROW 和 COL
属性,控制着,光标的位置。
你想移动,对他们付值就行了,
比如
向下移动。
stringgrid1.row:=stringgrid1.row+1;
你的别的问题,我没有时间看了,
不知道能不能帮到你
属性,控制着,光标的位置。
你想移动,对他们付值就行了,
比如
向下移动。
stringgrid1.row:=stringgrid1.row+1;
你的别的问题,我没有时间看了,
不知道能不能帮到你
调试欢乐多
To yrybye(BYRY) (2001-9-25 13:50:45)
我的问题是)。 比如一个CELLS的值是'abcdefg',
光标是在d和e 中间,我如何知道光标的位置。因为我想实现一个
功能是,比如当用户在对某一个CELLS中的值进行编辑,CELLS的值是'abcdefg',
而光标是在d和e之间,如果用户使用左移键,那么在STRINGGRID的缺省情况下
,光标是从d和e之间移动到c和d 之间, 问题是在当光标已经处于a之前,如果用户再使用左移键,那么我希望光标是
移动到前一个CELLS,也就是你说的COL + 1,
我的问题就是怎么判断光标已经位于当前CELLS的值的最前端了,当用户使用左移键,
然后我就可以通过COL + 1 实现了。 谢谢
你好,谢谢你的帮助,我先试试,只是没什么把握,你可以再给我一点详细的
帮助吗? 同时请其他的高手也帮忙看看,谢谢。
现在找也没找到。
好像是把它键转化。
我是这么做的。
当在dbgrid里头……
我帮你找出来再贴上来吧。
老天保佑你一定要找到,不过,我用的是STRINGGRID,不知道程序是否通用,不过
如果DBGRID可以实现,估计STRINGGRID也差不离了。
老兄,你说的是什么意思? 我不太明白?
你是不是通过button或是其它东西来控制stringGrid单元格的自由移动?
我在啊!
你有没有QQ ?
我不通过其他的东东,而是直接通过左右上下的按键来移动。
#pragma hdrstop#include "mouse.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TMouse *Mouse1;
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------void __fastcall TForm1::Button1Click(TObject *Sender)
{ DWORD time;
TPoint Point;
Mouse1=new TMouse();
Point.x=Button2->Left+30;
Point.y=Button2->Top+10;
MapWindowPoints(Handle,HWND_DESKTOP,&Point,1);
for(Point.x=Button2->Left+30;Point.x<550;Point.x++)
{
Application->ProcessMessages();
Mouse1->CursorPos=Point;
Sleep(1);
}
Sleep(500);
SendMessage(Button2->Handle,WM_LBUTTONDOWN,0,0);
Sleep(500);
SendMessage(Button2->Handle,WM_LBUTTONUP,0,0);
delete Mouse1;
}
//---------------------------------------------------------------------------void __fastcall TForm1::Button2Click(TObject *Sender)
{
ShowMessage("模拟单击!");
}
//---------------------------------------------------------------------------
Agui(阿贵)的经验蛮丰富的! 佩服佩服!
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
StdCtrls, ExtCtrls, Grids;type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
procedure StringGrid1GetEditText(Sender: TObject; ACol, ARow: Integer;
var Value: String);
private
{ Private declarations }
FOldProc: TWndMethod; // 原来的处理程序
edit: TEdit; // 那个编辑器 procedure NewHandler( var Msg: TMessage ); // 新的处理程序
function GetInplaceEdit: TEdit; // 取编辑框对象
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.DFM}
procedure TForm1.NewHandler(var Msg: TMessage);
var
CallOld: Boolean;
begin
CallOld := True;
if (edit.SelLength=0) and (Msg.Msg=WM_KEYDOWN) then
case Msg.WParam of
VK_DOWN:
if StringGrid1.Row<StringGrid1.RowCount-1 then
begin
StringGrid1.Row := StringGrid1.Row+1; // 下一行
CallOld := False; // 不要调用原来的了
StringGrid1.EditorMode := True; // 维持在编辑模式
edit.SelStart := 0; // 将插入点放在第一个字符之前
end; VK_UP:
if StringGrid1.Row>StringGrid1.FixedRows then
begin
StringGrid1.Row := StringGrid1.Row-1;
CallOld := False;
StringGrid1.EditorMode := True;
edit.SelStart := 0;
end; VK_LEFT:
if (edit.SelStart=0) and (StringGrid1.Col>StringGrid1.FixedCols) then
begin
StringGrid1.Col := StringGrid1.Col-1;
StringGrid1.EditorMode := True;
CallOld := False;
end; VK_RIGHT:
if (edit.SelStart=edit.GetTextLen) and (StringGrid1.Col<StringGrid1.ColCount-1) then
begin
StringGrid1.Col := StringGrid1.Col+1;
StringGrid1.EditorMode := True;
edit.SelStart := 0;
CallOld := False;
end; end; if CallOld then
FOldProc( Msg ); // 调用原来的
end;// 在即将变成编辑方式时调用,因为我担心是这时候才创建,不过看看源程序就知道了
procedure TForm1.StringGrid1GetEditText(Sender: TObject; ACol,
ARow: Integer; var Value: String);
begin
if Assigned( edit ) then
Exit; edit := GetInplaceEdit;
if not Assigned( edit ) then
Exit; with edit do
begin
FOldProc := WindowProc; // 先记住原来的处理程序
WindowProc := NewHandler; // 替换成新的
end;
end;function TForm1.GetInplaceEdit: TEdit;
begin
Result := TEdit( StringGrid1.Controls[0] );
end;end.
我刚才试了,但我只要将光标移动到CELLS里,程序就报内存溢出,不知道是为什么,我还再试,你可以帮我也看看吗?
Edit: TEdit;是放在private 里定义,还还是放在type里定义呢?
[email protected]
为什么我这里老是报错呢? 真是伤脑筋呀! 报错是在我双击某个CELLS是发生的。
根据你的经验,这是为什么呢?
我真不知道该怎么感谢你才好。 现在我只有通过加分谢你了,
补充 一下,程序出错是在我进入CELLS进行编辑的时候,程序报内存溢出。
你好,抱歉我直到现在才上得了网,在我上不了网的时候,我反复试了原琛序,但总时报内存溢出.,
我不知道这是硬件的问题,还是我的软件的问题.不过谢谢你的帮助,分数这就给你了,对了我在
http://www.csdn.net/expert/TopicView.asp?id=301327提了相同的问题,你在那里留个言
,我把分数也给你.同时我想问一下你,我是否可以把我现在遇到的内存溢出的问题作为新问题在
CSDN上挂出来.?再次感谢你的热心帮助.
function TForm1.GetInplaceEdit: TEdit;
begin
Result := TEdit( StringGrid1.Controls[0] ); //出错,报内存溢出的
end;
function TForm1.GetInplaceEdit: TEdit;
begin
//Result := TEdit( StringGrid1.Controls[0] ); //出错,报内存溢出的
Result := TEdit.Create(StringGrid1.Controls[0] );
end;
程序就不报错了,但并不触发NewHandel的事件。
是不是我这么改是错误的?