有關StringGrid的CELL問題 |
答題得分者是:m8815010
|
lin11112
初階會員 發表:42 回覆:83 積分:25 註冊:2003-02-17 發送簡訊給我 |
|
daniel__lee
高階會員 發表:18 回覆:124 積分:113 註冊:2002-11-10 發送簡訊給我 |
剛try了一下ok沒問題 應該是你想要的 //--------------------------------------------------------------------------- #include
------
~ 勿在浮沙上面築高塔 ~ |
lin11112
初階會員 發表:42 回覆:83 積分:25 註冊:2003-02-17 發送簡訊給我 |
|
pwipwi
版主 發表:68 回覆:629 積分:349 註冊:2004-04-08 發送簡訊給我 |
lin11112你好:
試試下面的Code,我只保證在BCB6的VCL下可以用,下一版可能就會失效了。另外..我這是破壞物件導向的行為....,能不要用就不要用。(不過誰叫他元件設計時,不開放TInplaceEdit) < class="code">
void __fastcall TForm1::StringGrid1DblClick(TObject *Sender)
{
TInplaceEdit* Editor =
dynamic_cast
|
lin11112
初階會員 發表:42 回覆:83 積分:25 註冊:2003-02-17 發送簡訊給我 |
|
pwipwi
版主 發表:68 回覆:629 積分:349 註冊:2004-04-08 發送簡訊給我 |
|
lin11112
初階會員 發表:42 回覆:83 積分:25 註冊:2003-02-17 發送簡訊給我 |
|
pwipwi
版主 發表:68 回覆:629 積分:349 註冊:2004-04-08 發送簡訊給我 |
這是最保險的程式,不過我跑出來的結果offset仍是636。如果你無法跑出來的話,可以用debuger檢查SringGrid1裡InplaceEditor有沒有配置出來。 請你先寫個測試程式看是否可行:只放一個StringGrid,Option只把goEditing設為true。在OnDblClick裡加上:
// 以下是動態尋找offset的方法 void __fastcall TForm1::StringGrid1DblClick(TObject *Sender) { for(unsigned int i = sizeof(TCustomControl); i < sizeof(TStringGrid);i+=4) { TInplaceEdit* Editor = dynamic_cast這麼做後,應該可以跑出結果: 最後再和你之前的程式比較,問題出在那 |
m8815010
版主 發表:99 回覆:372 積分:289 註冊:2003-11-13 發送簡訊給我 |
引言: 感謝daniel__lee大大 但是此方式會將CELL內的字串全部取出 但小弟要的功能是只取CELL內的部分字串 EX : CELL內如為"P123 /P234" 再DblClick後"/P234"會變成藍色 而小弟便只要取出"/P234"lin11112你好: >: < class="code">Unit1.h ~~ class TForm1 : public TForm { __published: // IDE-managed Components TStringGrid *StringGrid1; void __fastcall FormCreate(TObject *Sender); private: // User declarations TWndMethod OldStringGridWndProc; //add this line void __fastcall StringGridWndProc(TMessage& Message); //add this line public: // User declarations __fastcall TForm1(TComponent* Owner); }; Unit1.cpp ~~ TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { OldStringGridWndProc = StringGrid1->WindowProc; StringGrid1->WindowProc = StringGridWndProc; } //--------------------------------------------------------------------------- void __fastcall TForm1::FormCreate(TObject *Sender) { StringGrid1->RowCount=10; //測試環境給定 StringGrid1->ColCount=10; int cnt=0; for (int i=0;i<10;i ) for (int j=0;j<10;j ) StringGrid1->Cells[j][i]=IntToStr(cnt ) "test"; StringGrid1->EditorMode=true; //開啟可編輯模式 } //--------------------------------------------------------------------------- void __fastcall TForm1::StringGridWndProc(TMessage& Message) { OldStringGridWndProc(Message); if (Message.Msg==WM_CTLCOLOREDIT) { HWND hEditCtrl=(HWND)Message.LParam; //get the handle of the selected edit control char txt[128]; //suppose the length of text is about 128 ZeroMemory(txt,128); SendMessage(hEditCtrl,WM_GETTEXT,128,(LPARAM)txt); //get text value of the edit control int lResult; lResult=SendMessage(hEditCtrl,EM_GETSEL,NULL,NULL); //get the position you selected int spos=LOWORD(lResult); //get start position int epos=HIWORD(lResult); //get end position if (spos!=epos) //show text you selected on the "Form1->Caption" this->Caption=AnsiString(txt).SubString(spos 1,epos-spos); else this->Caption=""; } } 目前測還ok啦! |
lin11112
初階會員 發表:42 回覆:83 積分:25 註冊:2003-02-17 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |