StringGrid類詳解

事件句柄
1.StringGrid1GetEditText(Sender: TObject; ACol, ARow: Integer; var Value: string);
Options.goEditing = true才能觸發此事件。此事件在單元格進入可編輯狀態時觸發。參數ACol,ARow爲當前單元格的列號和行號(列號和行號都按順序從0開始編碼)。參數Value爲當前單元格中的內容。
2.StringGrid1GetEditMask(Sender: TObject; ACol, ARow: Integer; var Value: string);Options.goEditing = true才能觸發此事件。此事件在單元格進入可編輯狀態時觸發。參數ACol,ARow爲當前單元格的列號和行號(。參數Value內容未深入瞭解,不詳。
 
3.StringGrid1SelectCell(Sender: TObject; ACol, ARow: Integer; var CanSelect: Boolean);
選擇單元格時觸發。參數ACol,ARow爲當前單元格的列號和行號。參數CanSelect默認值True,設置爲False時,控制焦點不能移出當前單元格。
 
4.StringGrid1SetEditText(Sender: TObject; ACol, ARow: Integer; const Value: string);
觸發此事件的現象有多種情況。單元格內容變更時觸發。單元格編輯狀態撤銷時觸發。當單元格內容變更時,參數ACol,ARow爲當前單元格的列號和行號,參數Valuet爲當前輸入的內容。當單元格是從編輯狀態撤出時。參數ACol,ARow爲撤出前的單元格的列號和行號,參數Valuet爲單元格撤出前的內容。
另,焦點直接移出StringGrid1時又不觸發。
 
5.StringGrid1TopLeftChanged(Sender: TObject)
滾動條滾動時,StringGrid1的可視區域發生變化時觸發。在StringGrid1.LeftCol或者StringGrid1.TopRow屬性值變化時觸發。StringGrid1的可視區域發生變化,這2個屬性值會自動改變。
6.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState);
單元格重畫時觸發,很多操作都會觸發此事件,此事件觸發頻率很高,不適宜在此句柄做複雜處理。編輯單元格內容時不會觸發。
7.方法&屬性
總列數:StringGrid1.ColCount;
總行數:StringGrid1.RowCount;
固定列數:StringGrid1.FixedCols;
固定行數:StringGrid1.FixedRows;
當期活動單元格列號:StringGrid1.Col;
當期活動單元格行號:StringGrid1.Row;
訪問ACol列ARow行單元格內容:StringGrid1.Cells[ACol, ARow];
可見區域左邊可視的第一列序號:StringGrid1.LeftCol;排除固定列。
可見區域上邊可視的第一行序號:StringGrid1.TopRow;排除固定列。
 
Options.goEditing屬性控制列是否可以編輯。  //OnSelectCell句柄中動態設置可編輯列的方法。 
if ACol in [StringGrid1.FixedCols..StringGrid1.ColCount-1] then  
  StringGrid1.Options := StringGrid1.Options + [goEditing] 
else   
StringGrid1.Options := StringGrid1.Options - [goEditing];
 
StringGrid1.Objects[ACol, ARow] 可用於存儲各種對象,方便處理時使用。
當前活動單元格的LEFT值:StringGrid1.CellRect(StringGrid1.Col,StringGrid1.Row).Left;
當前活動單元格的Top值:StringGrid1.CellRect(StringGrid1.Col,StringGrid1.Row).Top;
當前活動單元格的列寬度值:StringGrid1.ColWidths[StringGrid1.Col];
當前活動單元格的行高度值:StringGrid1.RowHeights[StringGrid1.Row];
 

發佈了40 篇原創文章 · 獲贊 19 · 訪問量 9萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章