共用方式為


自訂 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 控制項中的基本格式化和樣式設定
提供主題描述如何修改控制項基本外觀和儲存格資料顯示格式。

另請參閱