C++ Builder StringGrid輸入2字元後,如何自動跳到下一格 |
尚未結案
|
mgwu
一般會員 發表:2 回覆:1 積分:0 註冊:2003-04-18 發送簡訊給我 |
|
DavidLo
高階會員 發表:17 回覆:225 積分:168 註冊:2004-07-21 發送簡訊給我 |
Hi! 我提供我的方法:
void __fastcall TFormTable::StringGrid1KeyPress(TObject *Sender, char &Key) { if(Key==VK_ESCAPE) { ModalResult = mrOk;//跳出視窗 } //enter -> next row,you have to decide left or bottom cell else if(Key==VK_RETURN) { StringGrid1->Row ;//next row same column //StringGrid1->Col ;//next left column return; } int col, row; // limit input length col = StringGrid1->Col; row = StringGrid1->Row; switch(col)//不同Column,不同寬度限制 { case 1: if(user_mode==2) { if(StringGrid1->Cells[col][row].Length()>=10) { Key = 0; FormMain->StatusBar1->SimpleText = "長度限制10!"; Beep(1200,100); } } else { if(StringGrid1->Cells[col][row].Length()>=20) { Key = 0; FormMain->StatusBar1->SimpleText = "長度限制20!"; Beep(1200,100); } } break; case 2: if(StringGrid1->Cells[col][row].Length()>=20) { Key = 0; FormMain->StatusBar1->SimpleText = "長度限制20!"; Beep(1200,100); } break; default: break; } } |
haman
中階會員 發表:46 回覆:137 積分:56 註冊:2005-03-10 發送簡訊給我 |
void __fastcall TForm1::StringGridKeyPress(TObject *Sender, char &Key) { if(StringGrid->Row >= StringGrid->RowCount-1 && StringGrid->Col >= StringGrid->ColCount-1) { StringGrid->Cells[StringGrid->Col][StringGrid->Row]=StringGrid->Cells[StringGrid->Col][StringGrid->Row] Key; ShowMessage("資料已滿"); return; } if(StringGrid->Cells[StringGrid->Col][StringGrid->Row].Length() == 2) { if(StringGrid->Col == StringGrid->ColCount-1) { StringGrid->Row ; StringGrid->Col = 0; } else StringGrid->Col ; } StringGrid->Cells[StringGrid->Col][StringGrid->Row]=StringGrid->Cells[StringGrid->Col][StringGrid->Row] Key; }==================================== 懂的不多,卻想學的更多,搞得不自覺的將問題複雜化@@ |
haman
中階會員 發表:46 回覆:137 積分:56 註冊:2005-03-10 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |