C 中DataGridView編輯狀態控制

2021-05-22 00:02:08 字數 605 閱讀 4481

datagridview的編輯狀態可以根據需求任意設定。

1、設定 datagridview1為唯讀

dgv.readonly = true;

此時,使用者的新增行操作和刪除行操作也被遮蔽了。

2、 設定 datagridview的第n列整列單元格為唯讀

dgv.columns[n].readonly = true;

3、 設定 datagridview 的第n行整行單元格為唯讀

dgv.rows[n].readonly = true;

4、 設定 datagridview的某個單元格為唯讀

dgv[m,n].readonly = true;//第m行第n列位置的單元格唯讀

5、根據第m列的值控制第n列的編輯狀態

在datagridview的cellbeginedit事件中新增一下**

if (e.columnindex == n)

//2010.4.19

設定列標題的對齊方式

dgv.columnheadersdefaultcellstyle.alignment   =   datagridviewcontentalignment.middlecenter; //居中顯示

C 中DataGridView操作技巧

複製 如下 region 操作datagridview 初始化datagridview屬性 要處理的datagridview 允許使用者新增行 允許使用者刪除行 是否顯示包含行標題的列 列標頭高度大小模式 是否多選 是否唯讀 列頭寬度 列選擇模式 public virtual void initse...

C 列印dataGridView中的資料

這幾天,我研究了以下c 如何列印datagridview中的資料,在網上 圖書館搜尋和查閱了一些內容,現總結一下 執行列印窗體中的資料操作 private void toolstripbutton2 click object sender,eventargs e 在窗體中繪製要列印的資料 priva...

C 中DataGridView移除選中行

定義乙個全域性datatable private datatable dtdata 查詢資料庫資料返回datatable賦給 dtdata,相信程式設計師都會,將 dtdata繫結到datagridview上 this.datagridview1.datasource dtdata 窗體如下圖 這個...