Trang Chủ | Diễn Đàn | Thành Viên (Đăng Ký) | Tìm Kiếm | Tutorial Room
Delphi - Lại Grid ?
Hỏi đáp, trao đổi về lập trình Delphi.
Chú ý: Pascal/Delphi FAQs
First page Previous page  (Page 1 )   1   Next page Last page
Lại Grid ?
Member
Member since
11:39 29-09-2001
Posts: 251
Fantasy Points: 3,861
info Posted at 07:53 15-03-2002 Move Move Topic   Pin/Unpin Pin Topic   Lock Lock Topic
Khi dùng StringGrid thì có cách nào mà gõ Enter thì cái hộp sáng nó chuyển sang cell bên phải không ? Tui hí hoáy làm sao khi gõ Enter thì CT nó "bắt phím" để hộp sáng nó nhảy sang cell bên phải.... cứ enter thì nó chạy hết column(n) thì nó tạo một "row" mới giống như khi ấn phím TAB ????

Need help !
Reply Reply   Quote Quote   Edit Edit   Delete Delete   Report Report
This post has been viewed 1,760 time(s). 1 direct repli(es) and 4 indirect repli(es).
Title Poster
info Lại Grid ?
 
answer Re: Lại Grid ?
kacao
Re: Lại Grid ?
Forum Moderator
Member since
05:21 19-08-2001
Posts: 922
Fantasy Points: 13,553
Rank
answer Posted at 08:56 15-03-2002
Reply to Lại Grid ? (elleHCSC)
elleHCSC:
Khi dùng StringGrid thì có cách nào mà gõ Enter thì cái hộp sáng nó chuyển sang cell bên phải không ? Tui hí hoáy làm sao khi gõ Enter thì CT nó "bắt phím" để hộp sáng nó nhảy sang cell bên phải.... cứ enter thì nó chạy hết column(n) thì nó tạo một "row" mới giống như khi ấn phím TAB ????

Need help !


bạn assign event OnKeyPress() cho cái StringGrid rồi bỏ cái này vô:

procedure TForm1.StringGrid1KeyPress(Sender: TObject; var Key: Char);
Var r: TGridRect;
begin
  if Key = #13 then // Phím Enter được nhấn
  with StringGrid1 do
  begin
    r := Selection; // Selection là vùng đang được chọn, đặt trường hợp chỉ có 1 ô được chọn
    if (r.left = pred(ColCount)) and (r.top = pred(RowCount)) then // nếu đang ở ô cuối cùng thì...
      RowCount := RowCount + 1; // thêm một dòng mới

    if r.left < pred(ColCount) then // nếu ô đang chọn không phải đang ở cột cuối
      inc(r.left) // nhảy sang cột kế tiếp
    else // còn không, nếu đang ở cột cuối
    begin
      r.left := FixedCols; // nhảy về cột đầu tiên
      if r.top < pred(RowCount) then // nếu ô đang chọn không phải đang ở dòng cuối...
        inc(r.top); // nhảy sang dòng tiếp theo
    end;
    r.BottomRight := r.TopLeft; // chắc rằng chỉ 1 ô được chọn
    Selection := r; // ok, cập nhật thanh sáng của StringGrid
  end;
end;


ps: hàm Pred tương đương với -1
Reply Reply   Quote Quote   Edit Edit   Delete Delete   Report Report
This post has been viewed 1,374 time(s). 2 direct repli(es) and 2 indirect repli(es).
Title Poster
answer Re: Lại Grid ?
 
answer Re: Lại Grid ?
elleHCSC
answer Re: Lại Grid ?
leduong_hatrung
Re: Lại Grid ?
Member
Member since
11:39 29-09-2001
Posts: 251
Fantasy Points: 3,861
answer Posted at 08:13 18-03-2002
Reply to Re: Lại Grid ? (kacao)
Duoc ru`i kintz a'. Nhung khi cu go~ het cac dong thi cai grid no khong tu dong keo xuong (scroll down) ma phai keo scroll bar thi cai dong minh moi nhap vao no moi hien len ?

How to do this ?
Reply Reply   Quote Quote   Edit Edit   Delete Delete   Report Report
This post has been viewed 1,362 time(s). 1 direct repli(es) and 0 indirect repli(es).
Title Poster
answer Re: Lại Grid ?
 
answer Re: Lại Grid ?
kacao
Re: Lại Grid ?
Forum Moderator
Member since
05:21 19-08-2001
Posts: 922
Fantasy Points: 13,553
Rank
answer Posted at 22:48 19-03-2002
Reply to Re: Lại Grid ? (elleHCSC)
elleHCSC:
Duoc ru`i kintz a'. Nhung khi cu go~ het cac dong thi cai grid no khong tu dong keo xuong (scroll down) ma phai keo scroll bar thi cai dong minh moi nhap vao no moi hien len ?

How to do this ?


Nếu muốn scroll xuống dòng cuối thì Elle thêm cái này:
Perform(WM_VSCROLL, MakeWord(SB_BOTTOM, 0), 0);
Reply Reply   Quote Quote   Edit Edit   Delete Delete   Report Report
This post has been viewed 1,350 time(s). 0 direct repli(es) and 0 indirect repli(es).
Re: Lại Grid ?
Member
Member since
19:50 22-12-2009
Posts: 1
Fantasy Points: 4
Rank
answer Posted at 01:12 29-12-2009
Reply to Re: Lại Grid ? (kacao)
Anh oi!
Giúp e với, e cũng muốn làm sự kiện tương tự nhưng e muốn khi nhấn enter thì nó nhảy từ dòng trên xuống dòng dưới trong diều kiện là cùng 1 cột ạ, làm ơn trả lời giúp e ạ, thanks bro trc nha
Reply Reply   Quote Quote   Edit Edit   Delete Delete   Report Report
This post has been viewed 918 time(s). 1 direct repli(es) and 0 indirect repli(es).
Title Poster
answer Re: Lại Grid ?
 
answer Re: Lại Grid ?
elleHCSC
Re: Lại Grid ?
Member
Member since
11:39 29-09-2001
Posts: 251
Fantasy Points: 3,861
answer Posted at 22:40 17-01-2010
Reply to Re: Lại Grid ? (leduong_hatrung)
oài cái này lâu quá rùi...

Bạn thử dùng event keydown xem nhé ví dụ sau nhé, tôi chỉ nhớ VD dưới khi gõ enter thì hộp sáng nó nhảy sang phải, còn để nó luôn "xuống dòng" thì dựa vào đó bạn chỉnh thêm chút chắc là được:

procedure TForm1.BangKeyDown(Sender: TObject; var Key: Word;  Shift: TShiftState);
var theRow, theCol, MaxCol, MaxRow : Integer;
begin
  if (not (goEditing in Bang.Options)) then Bang.Options:=Bang.Options + [goEditing];
  MaxCol := Bang.ColCount-1;
  MaxRow := Bang.RowCount-1;

  With Bang do begin
    //------------------------------------------- go phim ENTER;
    if (key=VK_RETURN) then begin
      theRow := Bang.Row;
      theCol := Bang.Col;
      if theCol < MaxCol then inc(theCol) else begin
        if theRow < MaxRow then inc(theRow);
        theCol := Bang.FixedCols;
      end;
      Bang.Col := theCol;
      Bang.Row := theRow;
    end; //key

  end;// bang;
end;
Reply Reply   Quote Quote   Edit Edit   Delete Delete   Report Report
This post has been viewed 732 time(s). 0 direct repli(es) and 0 indirect repli(es).
First page Previous page  (Page 1 )   1   Next page Last page

Permissions: Create Topic: No  |  Reply Topic: No  |  Attach File: No  |  Make Poll: No

Vietnamese Keyboard: AUTO TELEX VNI VIQR VIQR* OFF

Go top || Print page ||

All logos, trademarks and graphics artwork in this site are property of their respective owners.
Opinions expressed in articles within this site are those of their owners and may not reflect the opinion of TXBB.

TXBB: Home - Disclaimer - Help - Contact
Copyright (C) 2000-2006 TXBB. All rights reserved.

TreXanh Bulletin Board v2.0 (Build: #332 Nov 21, 2006)

DEBUG INFORMATION
Execution 0.172s - SQL used 4s - Concurrent process(es) 0