自訂 Windows Form DataGridView 控制項

控制項 DataGridView 提供數個屬性,可用來調整其儲存格、資料列和資料行的外觀和基本行為(外觀和風格)。 如果您有超越 類別功能的特殊需求,您也可以實作控制項的 DataGridViewCellStyle 擁有者繪圖,或藉由建立自訂儲存格、資料行和資料列來擴充其功能。

若要自行繪製儲存格和資料列,您可以處理各種 DataGridView 繪製事件。 若要修改現有的功能或提供新功能,您可以建立衍生自現有 DataGridViewCellDataGridViewColumnDataGridViewRow 型別的自有型別。 您也可以建立衍生類型來提供新的編輯功能,以在儲存格處於編輯模式時顯示您選擇的控制項。

本節內容

如何:在 Windows Forms DataGridView 控制項中自訂儲存格的外觀
描述如何處理 CellPainting 事件,以便手動繪製儲存格。

如何:在 Windows Forms DataGridView 控制項中自訂資料列的外觀
描述如何處理 RowPrePaintRowPostPaint 事件,以便使用跨越多個資料行的自訂、漸層背景和內容來繪製資料列。

操作說明:擴充儲存格和資料行的行為和外觀以自訂 Windows Forms DataGridView 控制項中的儲存格和資料行
描述如何建立衍生自 DataGridViewCellDataGridViewColumn 自訂類型,以便在滑鼠指標放在儲存格上時反白顯示儲存格。

操作說明:停用 Windows Forms DataGridView 控制項按鈕資料行中的按鈕
描述如何建立衍生自 DataGridViewButtonCellDataGridViewButtonColumn 的自訂類型,以便在按鈕資料行中顯示停用的按鈕。

操作說明:Windows Forms DataGridView 儲存格中的主控制項
描述如何實 IDataGridViewEditingControl 作 介面,並建立衍生自 DataGridViewCellDataGridViewColumn 自訂型別,以便在儲存格處於編輯模式時顯示 DateTimePicker 控制項。

參考

DataGridView
提供 DataGridView 控制項的參考文件。

DataGridViewCell
提供 類別的 DataGridViewCell 參考檔。

DataGridViewRow
提供 類別的 DataGridViewRow 參考檔。

DataGridViewColumn
提供 類別的 DataGridViewColumn 參考檔。

IDataGridViewEditingControl
提供 介面的 IDataGridViewEditingControl 參考檔。

Windows Forms DataGridView 控制項中的基本格式化和樣式設定
提供主題描述如何修改控制項基本外觀和儲存格資料顯示格式。

另請參閱