天天看點

C#.NET DataGridView 讓部分單元格變成隻讀的例子程式

 最近客戶有讓DataGridView中的部分單元格變成隻讀的需求,例如下面的效果圖

實作參考代碼如下:

// 這裡是部分控制單元格隻讀屬性的代碼實作

for (int i =0; i <this.grdRole.Rows.Count; i++)

           {

               DataRow dataRow = (this.grdRole.Rows[i].DataBoundItem as DataRowView).Row;

if (dataRow[BaseRoleTable.FieldAllowEdit].ToString().Equals("0")

|| dataRow[BaseRoleTable.FieldAllowDelete].ToString().Equals("0"))

               {

// this.grdRole.Rows[i].Cells[3].ReadOnly = true;

// this.grdRole.Rows[i].Cells[4].ReadOnly = true;

this.grdRole.Rows[i].Cells["colEnabled"].ReadOnly =true;

this.grdRole.Rows[i].Cells["colDescription"].ReadOnly =true;

               }

           }

本文轉自 jirigala 51CTO部落格,原文連結:http://blog.51cto.com/2347979/1199849,如需轉載請自行聯系原作者

繼續閱讀