共用方式為


如何:使 Windows Form DataGridView 控制項中的資料行成為唯讀

並非所有資料都是可編輯的。 在 DataGridView 控制項中,資料行 ReadOnly 屬性值會決定使用者是否能編輯該資料行中的儲存格。 如需如何讓控制項完全唯讀的資訊,請參閱 How to: Prevent Row Addition and Deletion in the Windows Forms DataGridView Control

在 Visual Studio 中會支援這項工作。 另請參閱 如何:使用設計 工具在 Windows Forms DataGridView 控制項中將資料行設為唯讀。

以程式設計方式將資料行設為唯讀

  • DataGridViewColumn.ReadOnly 屬性設為 true

    dataGridView1.Columns["CompanyName"].ReadOnly = true;
    
    dataGridView1.Columns("CompanyName").ReadOnly = True
    

編譯程式碼

這個範例需要:

另請參閱