TSTRINGRID 的ROW 和 COL
属性,控制着,光标的位置。
你想移动,对他们付值就行了,
比如
向下移动。
stringgrid1.row:=stringgrid1.row+1;
你的别的问题,我没有时间看了,
不知道能不能帮到你

解决方案 »

  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 实现了。    谢谢
       
      

  2.   

    处于编辑状态时,由Grid的一个子控件Edit接管了焦点,所以只要获得该控件对象,就可以用TEdit.SelStart来判断光标处在什么位置了。试试ActiveControl看能不能找到它,或者直接用TStringGrid.Controls数组来找。源程序恕我不能写出来了。如果试不出来,请mailto:[email protected]
      

  3.   

    To gui(阿贵) 回复于2001-9-25 19:21:44
    你好,谢谢你的帮助,我先试试,只是没什么把握,你可以再给我一点详细的
    帮助吗? 同时请其他的高手也帮忙看看,谢谢。
      

  4.   

    我以前做过。
    现在找也没找到。
    好像是把它键转化。
    我是这么做的。
    当在dbgrid里头……
    我帮你找出来再贴上来吧。
      

  5.   

    谢谢izvoo(瓦匠泥) (2001-9-25 22:51:01)
    老天保佑你一定要找到,不过,我用的是STRINGGRID,不知道程序是否通用,不过
    如果DBGRID可以实现,估计STRINGGRID也差不离了。 
      

  6.   

    To izvoo(瓦匠泥) (2001-9-26 1:36:23)
    老兄,你说的是什么意思? 我不太明白?
      

  7.   

    你还在吧?
    你是不是通过button或是其它东西来控制stringGrid单元格的自由移动?
      

  8.   

    To Nizvoo(瓦匠泥) 回复于2001-9-26 2:03:56
    我在啊!
    你有没有QQ ?
    我不通过其他的东东,而是直接通过左右上下的按键来移动。
      

  9.   

    #include <vcl.h>
    #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("模拟单击!");
    }
    //---------------------------------------------------------------------------
      

  10.   

    刚才用 Agui(阿贵)的方法(Tedit(Controls[i]).SelStart) 试了一下,可以做到.
    Agui(阿贵)的经验蛮丰富的! 佩服佩服!
      

  11.   

    哥们,我都提示你了。可是还得我花时间来写个例程。unit Unit1;interfaceuses
      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.
      

  12.   

    谢谢阿贵,我一定用心学DELPHI,我现在就试。 
      

  13.   

    To agui(阿贵) (2001-9-28 10:17:18)
    我刚才试了,但我只要将光标移动到CELLS里,程序就报内存溢出,不知道是为什么,我还再试,你可以帮我也看看吗?
      

  14.   

    To agui(阿贵) 
     Edit: TEdit;是放在private 里定义,还还是放在type里定义呢?
      

  15.   

    放在private里,放在type中就错了。奇怪,我这里没有问题,把你的源程序发给我:
    [email protected]
      

  16.   

    老兄,别急,我这里上网特慢,对了我的DELPHI是6。我用zip 文件给你发的
      

  17.   

    我用的是DELPHI6,运行环境是NT4.0,我的QQ是69445650,
    为什么我这里老是报错呢? 真是伤脑筋呀! 报错是在我双击某个CELLS是发生的。
    根据你的经验,这是为什么呢?
      

  18.   

    谢谢你的不厌其烦的指导,对于我这种生手,得到高手指点真是很幸运,
    我真不知道该怎么感谢你才好。 现在我只有通过加分谢你了,
    补充 一下,程序出错是在我进入CELLS进行编辑的时候,程序报内存溢出。
      

  19.   

    TO agui(阿贵) 
    你好,抱歉我直到现在才上得了网,在我上不了网的时候,我反复试了原琛序,但总时报内存溢出.,
    我不知道这是硬件的问题,还是我的软件的问题.不过谢谢你的帮助,分数这就给你了,对了我在
    http://www.csdn.net/expert/TopicView.asp?id=301327提了相同的问题,你在那里留个言
    ,我把分数也给你.同时我想问一下你,我是否可以把我现在遇到的内存溢出的问题作为新问题在
    CSDN上挂出来.?再次感谢你的热心帮助.
      

  20.   

    我调试发现程序是走到
    function TForm1.GetInplaceEdit: TEdit;
    begin
     Result := TEdit( StringGrid1.Controls[0] ); //出错,报内存溢出的
    end;
      

  21.   

    但当我将程序改成
    function TForm1.GetInplaceEdit: TEdit;
    begin
    //Result := TEdit( StringGrid1.Controls[0] ); //出错,报内存溢出的
    Result := TEdit.Create(StringGrid1.Controls[0] );    
    end;    
    程序就不报错了,但并不触发NewHandel的事件。
    是不是我这么改是错误的?