Q&A

  • 마우스로 multiselect도 하면서 Edit도 할려면?
스트링그리드의 OPtions에서 goEditing을 True로 만들면

마우스로 multiselect가 안돼고요. False로 놓으면 multiselect는

되지만 Edit가 안돼는데 어떻게하면 multiselect도 되고 DbClick하면

Edit도 되는지 알려주세요.

1  COMMENTS
  • Profile
    최석기 2000.09.06 03:18
    안녕하세요.

    델파이세상(http://www.freechal.com/delphiworld)에 최석기입니다..



    님 질문을 보구 함 잼있을꺼 같아서 만들어 봤습니다..

    그냥 허접하게 만들어서 버그가 있을지도 모르겠네요..



    그냥 참고만 하세요..

    소스 다 올립니다..



    unit Unit1;



    interface



    uses

    Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,

    Grids, DBGrids;



    type

    TForm1 = class(TForm)

    StringGrid1: TStringGrid;

    procedure FormCreate(Sender: TObject);

    procedure StringGrid1MouseDown(Sender: TObject; Button: TMouseButton;

    Shift: TShiftState; X, Y: Integer);

    procedure StringGrid1MouseMove(Sender: TObject; Shift: TShiftState; X,

    Y: Integer);

    procedure StringGrid1MouseUp(Sender: TObject; Button: TMouseButton;

    Shift: TShiftState; X, Y: Integer);

    private

    { Private declarations }

    Capturing : bool;

    Captured : bool;

    StartPlace : TPoint;

    EndPlace : TPoint;

    public

    { Public declarations }

    end;



    var

    Form1: TForm1;



    implementation



    {$R *.DFM}



    function MakeRect(Pt1 : TPoint;

    Pt2 : TPoint) : TRect;

    begin

    if pt1.x < pt2.x then begin

    Result.Left := pt1.x;

    Result.Right := pt2.x;

    end else begin

    Result.Left := pt2.x;

    Result.Right := pt1.x;

    end;

    if pt1.y < pt2.y then begin

    Result.Top := pt1.y;

    Result.Bottom := pt2.y;

    end else begin

    Result.Top := pt2.y;

    Result.Bottom := pt1.y;

    end;

    end;



    procedure TForm1.FormCreate(Sender: TObject);

    var

    i, j: Integer;

    begin

    // Column의 title을 만든다

    for i := 1 to StringGrid1.ColCount - 1 do

    StringGrid1.Cells[i, 0] := Char(Ord('A')+i-1);



    // Row의 title을 만든다

    for i := 1 to StringGrid1.RowCount - 1 do

    StringGrid1.Cells[0, i] := IntToStr(i);;



    // 임의의 자료를 만들어서 각 cell에 입력합니다

    for i := 1 to StringGrid1.ColCount - 1 do

    for j := 1 to StringGrid1.RowCount - 1 do

    StringGrid1.Cells[i, j] := Format('%.0n', [i * j * 10000.0]);



    //Editing는 가능, MultiSelect는 불가능 옵션

    StringGrid1.Options := [goFixedVertLine,goFixedHorzLine,goVertLine,goHorzLine,goEditing];

    end;



    procedure TForm1.StringGrid1MouseDown(Sender: TObject;

    Button: TMouseButton; Shift: TShiftState; X, Y: Integer);

    begin

    if Captured then

    DrawFocusRect(StringGrid1.Canvas.Handle,

    MakeRect(StartPlace,

    EndPlace));

    StartPlace.x := X;

    StartPlace.y := Y;

    EndPlace.x := X;

    EndPlace.y := Y;

    DrawFocusRect(StringGrid1.Canvas.Handle,

    MakeRect(StartPlace,

    EndPlace));

    Capturing := true;

    Captured := true;

    end;



    procedure TForm1.StringGrid1MouseMove(Sender: TObject; Shift: TShiftState;

    X, Y: Integer);

    begin

    if Capturing then begin

    DrawFocusRect(StringGrid1.Canvas.Handle,

    MakeRect(StartPlace,

    EndPlace));

    EndPlace.x := X;

    EndPlace.y := Y;

    DrawFocusRect(StringGrid1.Canvas.Handle,

    MakeRect(StartPlace,

    EndPlace));

    end;

    end;



    procedure TForm1.StringGrid1MouseUp(Sender: TObject; Button: TMouseButton;

    Shift: TShiftState; X, Y: Integer);

    var

    SelectedRectangle: TGridRect;

    CoordTopLeft, CoordBottomRight: TGridCoord;

    ACol, ARow: Longint;

    begin

    Capturing := false;



    CoordTopLeft := StringGrid1.MouseCoord(StartPlace.x,StartPlace.y);

    CoordBottomRight := StringGrid1.MouseCoord(EndPlace.x,EndPlace.y);



    with StringGrid1 do begin

    SelectedRectangle.TopLeft := CoordTopLeft;

    SelectedRectangle.BottomRight := CoordBottomRight;

    end;

    StringGrid1.Selection:= SelectedRectangle;

    end;



    end.





    호야 wrote:

    > 스트링그리드의 OPtions에서 goEditing을 True로 만들면

    > 마우스로 multiselect가 안돼고요. False로 놓으면 multiselect는

    > 되지만 Edit가 안돼는데 어떻게하면 multiselect도 되고 DbClick하면

    > Edit도 되는지 알려주세요.