線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:4686
推到 Plurk!
推到 Facebook!

請教 BCB 有關於 StringGrid 的用法?

答題得分者是:senso
liolinke
一般會員


發表:1
回覆:0
積分:0
註冊:2009-04-23

發送簡訊給我
#1 引用回覆 回覆 發表時間:2009-11-11 18:47:09 IP:118.170.xxx.xxx 訂閱
請問各位大大!
小弟想寫一個 在StringGrid 可以顯示 decimal / Hex 的功能,但是遇到一個問題!
單純顯示是 ok 的。
但是當我要檢查使用者輸入的是不是十六進位的 A ~ F 時我發現如果使用 StringGrid1SetEditText 事件,如果我將
StringGrid1->Cells[ACol][ARow]= Value.Delete(Value.Length(),1);
可以刪除一個字但是整個 Cell 中的文字會被選取,要輸入下一個字的話要先將滑鼠移到原來的 cell 中,否則 StringGrid 會刪除原來的內容。
請問有沒有什麼好的方法可行!
ps這是一個專案!小弟是BCB 新手。希望各位先進指教!
//---------------------------------------------------------------------------
// in Decimal mode
void __fastcall TForm1::RadioButton6Click(TObject *Sender)
{
hexordec = "Dec";
Label9->Caption = hexordec;

// change StringGrid1
for(int i=1;iColCount;i )
StringGrid1->Cells[i][1] = StringGrid1->Cells[i][1].ToInt();
}
//---------------------------------------------------------------------------
// in Hex mode
void __fastcall TForm1::RadioButton7Click(TObject *Sender)
{
hexordec = "Hex";
Label9->Caption = hexordec;


// change StringGrid1
for(int i=1;iColCount;i )
StringGrid1->Cells[i][1] = "0x" StringGrid1->Cells[i][1].IntToHex(StrToInt(StringGrid1->Cells[i][1]),6);

}
//---------------------------------------------------------------------------
// check what kind of input format (decimal or hex)
void __fastcall TForm1::StringGrid1SetEditText(TObject *Sender, int ACol,
int ARow, const AnsiString Value)
{

//=======================================================

AnsiString temp = Value.SubString(Value.Length(),1);

if((Label9->Caption == "Dec") && (temp < "0" || temp > "9"))
{
StringGrid1->Cells[ACol][ARow] = Value.Delete(Value.Length(),1);

}
if(Label9->Caption == "Hex")
{
//temp = temp.UpperCase();

if((temp >= "0" && temp <= "9")||(temp >= "A" && temp <= "F"))
{
temp = Value temp;
StringGrid1->Cells[ACol][ARow] = temp.UpperCase();
}else
StringGrid1->Cells[ACol][ARow] = Value.Delete(Value.Length(),1);
}
}
編輯記錄
liolinke 重新編輯於 2009-11-12 09:37:40, 註解 無‧
senso
高階會員


發表:5
回覆:126
積分:226
註冊:2003-11-27

發送簡訊給我
#2 引用回覆 回覆 發表時間:2009-11-12 10:35:38 IP:61.219.xxx.xxx 訂閱

參考TStringGrid之selTxt
http://delphi.ktop.com.tw/board.php?cid=168&fid=913&tid=31652
在SetEditText再指定SelStart
[code cpp]
((TSG *)StringGrid1)->InplaceEditor->SelStart=Value.Length();
[/code]

不過你的code只檢查最後一個字,如果使用者從中間key字的話會判斷不到吧?

還是寫在KeyPress裡過濾掉吧
[code cpp]
if(!((Key>='a' && Key<='f') ||
(Key>='A' && Key<='F') ||
(Key>='0' && Key<='9') )) Key=NULL;

[/code]
系統時間:2024-04-25 21:22:18
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!