stringgrid的用法(跑下一個欄位) |
尚未結案
|
pricejit2
一般會員 發表:53 回覆:18 積分:14 註冊:2005-01-28 發送簡訊給我 |
|
supman
尊榮會員 發表:29 回覆:770 積分:924 註冊:2002-04-22 發送簡訊給我 |
您好:
如下,請參考.
procedure TForm1.StringGridKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (Key=13) then
StringGrid.Row:=StringGrid.Row 3;
end; 我剛剛看了您另外一偏,您說不用按Enter,就跳下一行,那請教一下,您跳一行的觸發點是蛇麼?長度??如果是改成以下這樣 procedure TForm1.StringGridKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (Length(StringGrid.Cells[StringGrid.Col,StringGrid.Row])=2)//如果輸入了2各就跳下一行
StringGrid.Row:=StringGrid.Row 1;
end; 發表人 - supman 於 2005/06/05 12:30:19
|
pricejit2
一般會員 發表:53 回覆:18 積分:14 註冊:2005-01-28 發送簡訊給我 |
|
supman
尊榮會員 發表:29 回覆:770 積分:924 註冊:2002-04-22 發送簡訊給我 |
請問您有測試過我第二段程式嗎?
procedure TForm1.StringGridKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (Length(StringGrid.Cells[StringGrid.Col,StringGrid.Row])=2)//如果輸入了2各就跳下一行
StringGrid.Row:=StringGrid.Row 1;
end;
除了輸入外,哪裡有按Enter鑑?? 發表人 - supman 於 2005/06/05 14:46:01
|
wameng
版主 發表:31 回覆:1336 積分:1188 註冊:2004-09-16 發送簡訊給我 |
一般以目前的掃瞄槍,都是以模擬鍵盤輸入的方式。 處理的方法:
1. 在 Form 的 KeyPress 處理。而非Grid,主要是焦點不在Grid 時。會無法攔截到輸入的鍵值。當然 Form 的 KeyPreview := True; 2. 一般掃瞄槍,會在輸入完畢後自動代 Enter 鍵。
如:ScanID 為 Form 的私有變數。
procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char); var ARow :Integer; begin Case Key of #13 :if ScanID<>'' then begin { 找到該商品位置 } // ARow := StringGrid1.Cols[2].IndexOf(SCanID); StringGrid1.Row := StringGrid1.Row 1; ScanID :=''; end; else ScanID := ScanID Key; end; end;~~~~~~~~~~~ 難得聰明,常常糊塗。 ~~~~~~~~~~~ |
pricejit2
一般會員 發表:53 回覆:18 積分:14 註冊:2005-01-28 發送簡訊給我 |
各位大大
若我想掃描槍掃一次,自動跳下一格,然後掃進的那個欄位的最左邊的checkbox會自動打勾,有辦法嗎 邏輯一直不對 請高手幫幫忙
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Grids; type TForm1 = class(TForm) StringGrid1: TStringGrid; procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); procedure StringGrid1SelectCell(Sender: TObject; ACol, ARow: Integer; var CanSelect: Boolean); procedure StringGrid1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure FormKeyPress(Sender: TObject; var Key: Char); procedure setzero; procedure FormCreate(Sender: TObject); private ScanID:string; { Private declarations } public keyin:integer; diff:integer; testrow,testcol:integer; remeber:integer; { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure tform1.setzero; begin remeber:=remeber 1; end; procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); //只是劃框用 //由左而右執行一次所有欄位畫完 var Flags : Integer; begin begin if ((ARow>0) and (ACol=0)) then //定要row>0不然從cells【0,0】開始 begin StringGrid1.Canvas.FillRect(Rect); Inc(Rect.Top,4); Dec(Rect.Bottom,4); Flags := DFCS_BUTTONCHECK; //第一列的框打勾的條件 第三列的框打勾的條件 不同列的條件 if (((StringGrid1.Cells[ACol,ARow]='1') or (keyin=1) or(arow=testrow)) and (remeber=testrow)) then//or(arow=remeber) then//and(remeber=arow)) then//and (diff=1)) then //是否打勾的判定 begin Flags := Flags or DFCS_CHECKED; //設定勾 keyin:=0; //畫的function end; DrawFrameControl(StringGrid1.Canvas.Handle,Rect,DFC_BUTTON,Flags ); end; end; end; procedure TForm1.StringGrid1SelectCell(Sender: TObject; ACol, ARow: Integer; var CanSelect: Boolean); begin { 若Grid 不允許修改編輯。則可省略此段處理} if ((ARow>0) and (ACol=0)) then begin StringGrid1.Options := StringGrid1.Options - [goEditing]; StringGrid1.EditorMode := False; end else StringGrid1.Options := StringGrid1.Options [goEditing]; end; procedure TForm1.StringGrid1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin With StringGrid1 do begin if ((row>0) and (col=0)) or ((row>0) and (col=3)) then begin testrow:=row; testcol:=col; Cells[Col,Row] := inttostr(ORD(Cells[Col,Row]<>'1')); //打勾之後cells[col,row]=0 if (col=3) and (row>0) then //重點 begin col:=col-3; //會跳至selectcell keyin:= ORD(Cells[Col,Row]<>'1'); //有點就得到1 setzero; end; //col:=col 3; { if cells[col,row 1]<>cells[col-3,row] then //不同列比 begin diff:=1; end;} end; end; end; procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char); begin Case Key of #13 :if ScanID<>'''' then begin { 找到該商品位置 } // ARow := StringGrid1.Cols[2].IndexOf(SCanID); //stringgrid1.Cells[stringgrid1.col,stringgrid1.row]:=inttostr(ORD(stringgrid1.Cells[stringgrid1.col,stringgrid1.row]<>'1')); StringGrid1.Row := StringGrid1.Row 1; stringgrid1.Cells[stringgrid1.Col,stringgrid1.Row]:='0'; ScanID :=''''; end; else ScanID := ScanID Key; end; end; procedure TForm1.FormCreate(Sender: TObject); begin remeber:=0; end; end.發表人 - wameng 於 2005/06/08 12:15:07 |
wameng
版主 發表:31 回覆:1336 積分:1188 註冊:2004-09-16 發送簡訊給我 |
|
pricejit2
一般會員 發表:53 回覆:18 積分:14 註冊:2005-01-28 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |