StringGrid如何觸發其他StringGrid做Focus的動作? |
答題得分者是:m8815010
|
palw
初階會員 發表:45 回覆:89 積分:26 註冊:2003-02-24 發送簡訊給我 |
|
m8815010
版主 發表:99 回覆:372 積分:289 註冊:2003-11-13 發送簡訊給我 |
引言: 各位,您好: 請問 因為需要顯示的結果太多了,所以我拉了兩個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 發送簡訊給我 |
|
palw
初階會員 發表:45 回覆:89 積分:26 註冊:2003-02-24 發送簡訊給我 |
您好..我已經推敲出來了...
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 發送簡訊給我 |
引言: 您好..我已經推敲出來了... TGridRect myRect; myRect.Left = 8;//因為StringGrid總共有8欄 myRect.Top = ARow; myRect.Bottom = ARow; StringGrid2->Selection=myRect; //設定StringGrid2被選擇的Cells StringGrid2->TopRow=StringGrid1->TopRow; //設定StringGrid2現在的最上一行 雖然是比較笨的方法..但我大概了解該怎麼做了..Thank youpalw你好< >: 哦,你要的是這樣的話,那這樣改也許應該完善些< >: 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 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |