| ▼ Mr.XRAYさん
 こんにちは、Saraです。
 
 いろいろと、いじって見て思ったのですが、
 DrawCellでEditにフォーカスを与えるときに、マウスの位置が
 StringGrid上にあるかどうかを確認しないと、StringGrid外に
 ボタン等を配置したときに、ボタン等のイベントが起きないです。
 (ボタンを連射しているとたまにイベントが起きますが(^^; )
 
 なので、こんな感じで・・・(もっと良い方法があるかな・・・ Syakeさん)
 
 procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
 Rect: TRect; State: TGridDrawState);
 var APos : TPoint;
 begin
 //選択セルの場合のみ処理
 if gdSelected in State then begin
 //エディトを表示する列の番号は2
 if ACol = 2 then begin
 GetCursorPos(APos);
 if FindVCLWindow(APos) = StringGrid1 then begin
 SetWindowPos(Edit1.Handle,
 0,
 Rect.Left + StringGrid1.Left + 1,
 Rect.Top,
 Rect.Right - Rect.Left,
 Rect.Bottom - Rect.Top + 2,
 SWP_NOZORDER);
 Edit1.Visible := True;
 Edit1.SetFocus;
 end;
 end else begin
 if Edit1.Visible then begin
 Edit1.Visible := False;
 StringGrid1.SetFocus;
 end;
 end;
 end;
 end;
 
 
 |