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

StringGrid如何觸發其他StringGrid做Focus的動作?

答題得分者是:m8815010
palw
初階會員


發表:45
回覆:89
積分:26
註冊:2003-02-24

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-11-01 13:50:13 IP:61.62.xxx.xxx 未訂閱
各位,您好: 請問 因為需要顯示的結果太多了,所以我拉了兩個StringGrid來顯示資料. 但是我希望第一個StringGrid選中第幾列時,第二個StringGrid也會自動移到那一列..不知各位先進有什麼好方法嗎?謝謝!
m8815010
版主


發表:99
回覆:372
積分:289
註冊:2003-11-13

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-11-01 14:35:21 IP:61.63.xxx.xxx 未訂閱
引言: 各位,您好: 請問 因為需要顯示的結果太多了,所以我拉了兩個StringGrid來顯示資料. 但是我希望第一個StringGrid選中第幾列時,第二個StringGrid也會自動移到那一列..不知各位先進有什麼好方法嗎?謝謝!
palw你好: class="code"> void __fastcall TForm1::FormCreate(TObject *Sender) { StringGrid1->RowCount=10; //測試環境給定 - StringGrid1 StringGrid1->ColCount=10; int cnt=0; for (int i=0;i<10;i ) { for (int j=0;j<10;j ) StringGrid1->Cells[j][i]=cnt ; } StringGrid2->RowCount=10; //測試環境給定 - StringGrid2 StringGrid2->ColCount=10; cnt=0; for (int i=0;i<10;i ) { for (int j=0;j<10;j ) StringGrid2->Cells[j][i]=cnt ; } } //--------------------------------------------------------------------------- void __fastcall TForm1::StringGrid1SelectCell(TObject *Sender, int ACol, int ARow, bool &CanSelect) { TGridRect myRect; myRect.Left = ACol; myRect.Top = ARow; myRect.Right = ACol; myRect.Bottom = ARow; StringGrid2->Selection=myRect; //設定StringGrid2被選擇的Cells StringGrid2->TopRow=StringGrid1->TopRow; //設定StringGrid2現在的最上一行 } //---------------------------------------------------------------------------
palw
初階會員


發表:45
回覆:89
積分:26
註冊:2003-02-24

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-11-01 14:58:10 IP:61.62.xxx.xxx 未訂閱
Dear m8815010 , 您好 :       您的方式很棒,已經很接近是我想做的效果..可能是原理我還不是很清楚吧..還有個問題想請教您,因為我想做到整列選擇的功能.而且非只有一個欄位被選取..感謝您...
palw
初階會員


發表:45
回覆:89
積分:26
註冊:2003-02-24

發送簡訊給我
#4 引用回覆 回覆 發表時間:2004-11-01 15:36:27 IP:61.62.xxx.xxx 未訂閱
您好..我已經推敲出來了... TGridRect myRect; myRect.Left = 8;//因為StringGrid總共有8欄 myRect.Top = ARow; myRect.Bottom = ARow; StringGrid2->Selection=myRect; //設定StringGrid2被選擇的Cells StringGrid2->TopRow=StringGrid1->TopRow; //設定StringGrid2現在的最上一行 雖然是比較笨的方法..但我大概了解該怎麼做了..Thank you
m8815010
版主


發表:99
回覆:372
積分:289
註冊:2003-11-13

發送簡訊給我
#5 引用回覆 回覆 發表時間:2004-11-01 16:12:10 IP:61.63.xxx.xxx 未訂閱
引言: 您好..我已經推敲出來了... TGridRect myRect; myRect.Left = 8;//因為StringGrid總共有8欄 myRect.Top = ARow; myRect.Bottom = ARow; StringGrid2->Selection=myRect; //設定StringGrid2被選擇的Cells StringGrid2->TopRow=StringGrid1->TopRow; //設定StringGrid2現在的最上一行 雖然是比較笨的方法..但我大概了解該怎麼做了..Thank you
palw你好< >: 哦,你要的是這樣的話,那這樣改也許應該完善些< >:

 TGridRect myRect;
 myRect.Left   = 1;    //總是固定整列全選(假設default有10列)
 myRect.Top    = ARow;
 myRect.Right  = 10;   //總是固定整列全選
 myRect.Bottom = ARow;     StringGrid2->Selection=myRect;             //設定StringGrid2被選擇的Cells
 StringGrid2->TopRow=StringGrid1->TopRow;   //設定StringGrid2現在的最上一行
另外剛剛在想這樣的效果,我以為你是要這種的: < class="code"> ~~ TForm1 *Form1; bool If_Sel=false; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::FormCreate(TObject *Sender) { StringGrid1->RowCount=10; //測試環境給定 - StringGrid1 StringGrid1->ColCount=10; int cnt=0; for (int i=0;i<10;i ) { for (int j=0;j<10;j ) StringGrid1->Cells[j][i]=cnt ; } StringGrid2->RowCount=10; //測試環境給定 - StringGrid2 StringGrid2->ColCount=10; cnt=0; for (int i=0;i<10;i ) { for (int j=0;j<10;j ) StringGrid2->Cells[j][i]=cnt ; } } //--------------------------------------------------------------------------- void __fastcall TForm1::StringGrid1SelectCell(TObject *Sender, int ACol, int ARow, bool &CanSelect) { If_Sel=true; StringGrid2->TopRow=StringGrid1->TopRow; //設定StringGrid2現在的最上一行 } //--------------------------------------------------------------------------- void __fastcall TForm1::StringGrid1MouseMove(TObject *Sender, TShiftState Shift, int X, int Y) { if (If_Sel) { StringGrid2->TopRow=StringGrid1->TopRow; StringGrid2->Selection=StringGrid1->Selection; } } //--------------------------------------------------------------------------- void __fastcall TForm1::StringGrid1MouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { If_Sel=false; }
palw
初階會員


發表:45
回覆:89
積分:26
註冊:2003-02-24

發送簡訊給我
#6 引用回覆 回覆 發表時間:2004-11-01 19:08:28 IP:61.62.xxx.xxx 未訂閱
非常感謝您!
系統時間:2024-05-19 8:44:22
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!