最近客户有让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,如需转载请自行联系原作者

C#.NET DataGridView 让部分单元格变成只读的例子程序相关推荐

  1. datagrid设置单元格边框_如何设置datagridview某一个单元格的边框样式

    如何设置datagridview某一个单元格的边框样式 关注:153  答案:2  mip版 解决时间 2021-01-27 02:18 提问者浅沫记忆 2021-01-26 14:32 如何设置da ...

  2. Windows Forms DataGridView 中合并单元格

    Windows Forms DataGridView 没有提供合并单元格的功能,要实现合并单元格的功能就要在CellPainting事件中使用Graphics.DrawLine和 Graphics.D ...

  3. DataGridView 中合并单元格

    Windows Forms DataGridView 没有提供合并单元格的功能,要实现合并单元格的功能就要在CellPainting事件中使用Graphics.DrawLine和 Graphics.D ...

  4. DataGridview单击某个单元格选中一行

    DataGridview如何单击某个单元格选中一行? 代码的方式设置 this.dataGridView1.SelectionMode = DataGridViewSelectionMode.Full ...

  5. datagridview 单击某个单元格选中一行

    首先: this.dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;//设置为整行被选中 然后,在dataGr ...

  6. dataGridView获得选中单元格行索引

    获得选中单元格行索引 (1) int _tempIndex =-1: private void dgv_TemplateMsg_CellClick(object sender, DataGridVie ...

  7. Winform DataGridView列的单元格中动态添加图片和文字

    先上图在说,第二列中图片和文字的样式 1.需要重写DataGridViewTextBoxColumn,新建类TextAndImageColumn.cs 1 using System; 2 using ...

  8. C# DataGridView 获取当前单元格输入内容

    /// <summary> /// 编辑控件显示事件 /// </summary> /// <param name="sender"></ ...

  9. DataGridView取得或者修改当前单元格的内容

    当前单元格指的是 DataGridView 焦点所在的单元格,它可以通过 DataGridView 对象的 CurrentCell 属性取得.如果当前单元格不存在的时候,返回Nothing(C#是nu ...

最新文章

  1. Microsoft Agrees to Acquire ProClarity
  2. Exchange 2013部署系列之(五)NLB负载均衡
  3. HDU2032杨辉三角(C++)
  4. 密度图的密度估计_箱形图、小提琴图、直方图……统统可以卡通化!
  5. 9读书1-我在义务发财(1)
  6. scala 方法重载_Scala中的方法重载
  7. android fragment fragmenttransaction,Android FragmentTransaction 常用方法总结
  8. Nodejs创建简单的Bot
  9. centos赋予访问权限
  10. 不开机win7计算机还原,Win7开机出现Windows错误恢复解决方法
  11. 2020年中国干旱灾害受灾面积、饮水困难人口数量及造成经济作物损失分析[图]
  12. 各种符号用英语怎么念
  13. 【计算机视觉】Lecture 11:LoG和DoG滤波算子
  14. UTM——统一威胁管理
  15. MSDTC 分布式事务错误解决
  16. 15-英特尔驱动下载安装
  17. null == 什么意思? 和 ==null是不是一个意思啊?
  18. 【ArcGIS】ArcGIS Editor for OpenStreetMap 各版本稳定下载链接
  19. 写代码应该用什么字体?
  20. 诺顿360偷偷挖矿被怒喷 官方却说:都是为了用户好

热门文章

  1. android http封装类,HTTP封装类 工具类 For Android
  2. python点操作符语法,Python 语法之操作符和表达式
  3. 第一个go程序: HTTP 服务示例
  4. 三次iframe框架切换
  5. 关于软件测试工程师所应该具备的能力,就业前景还有适合女生从事吗?
  6. oracle 错误码1438,一次ora-01438错误的处理
  7. asp.net core文档下载_推荐一个必备的开源项目 (附下载链接)
  8. build tut framework on ubuntu
  9. mysql 1539_MySQL:半同步(三)从库端初始化和回调函数
  10. 高等院校计算机考试等级,全国高等院校计算机等级试考试大纲.doc