转,,,,C#中关于DataGridView行和列的背景色-前景色设置
2013-01-11 15:38
288 查看
C#中关于DataGridView行和列的背景色-前景色设置
关于DataGridView行和列的背景色-前景色设置1.设定DataGridView全部单元格的Style
DataGridView内所有单元格的Style变更,可以使用DataGridView对象的DefaultCellStyle属性实现。
?
?
DataGridViewCell.Style属性可以对单一的单元格的Style进行变更设定。
如下面的例子,只对(0, 0)单元格的背景色设定为粉红色。
?
DataGridViewColumn.DefaultCellStyle属性,可以对列的单元格Style进行变更设定。 DataGridViewRow.DefaultCellStyle属性,可以对行的单元格Style进行变更设定。
如下面的例子,第一列的单元格的背景色为淡蓝色,第一行的单元格的背景色为淡灰色。
?
DataGridView.AlternatingRowsDefaultCellStyle属性,可以变更DataGridView的奇数行的单元格 Style。
如下面的例子,奇数行的单元格的背景色设定为黄绿色
?
列Header的单元格style的变更,可以使用,DataGridView.ColumnHeadersDefaultCellStyle属性实现。行 Header的单元格Style的变更,可以使用DataGridView.RowHeadersDefaultCellStyle属性实现。但是,Header 的是左侧的单元格需要通过DataGridView.TopLeftHeaderCell属性,取得的DataGridViewHeaderCell对象的单 元格Style进行设定。
如下面的例子,列Header的背景色为象牙色,行Header的背景色为橙色。
?
关于优先顺序
设定单元格Style的属性有优先顺序的。顺序从高到低如下所示。
1). DataGridViewCell.Style
2). DataGridViewRow.DefaultCellStyle
3). DataGridView.AlternatingRowsDefaultCellStyle
4). DataGridView.RowsDefaultCellStyle
5). DataGridViewColumn.DefaultCellStyle
6). DataGridView.DefaultCellStyle
接下来是Header的单元格Style属性的优先顺序。
1). DataGridViewCell.Style
2). DataGridView.RowHeadersDefaultCellStyle
3). DataGridView.ColumnHeadersDefaultCellStyle
4). DataGridView.DefaultCellStyle
单元格本身的设定的Style是最优先的。
相关文章推荐
- C#中关于DataGridView行和列的背景色-前景色设置
- C#中关于DataGridView行和列的背景色-前景色设置
- C#中关于DataGridView行和列的背景色-前景色设置
- 关于POI设置背景色的问题
- 程序入口地址的直接定制表【 (1) 清屏(2) 设置前景色 (3) 设置背景色 (4) 向上滚动一行】
- C# 关于Form的一些属性设置
- 关于c# winForm窗体最大化的设置
- 关于c# 未将对象引用设置到对象实例的问题(不解。。。)是不是数据库的问题....
- C#更改控制台文本的前景色和背景色
- C#更改控制台文本的前景色和背景色
- Swing之JTable篇设置表格选中行的前景色和背景色
- Photoshop脚本 > 设置前景色和背景色
- 关于C# wpf DataGrid单元格双击设置单元格内容
- Enabled设置为False时,前景色和背景色也不改变的TextBox 并居中
- 文档前景色和背景色设置
- 关于c# winForm窗体最大化的设置
- IDA Pro 7.0皮肤插件的安装与深色主题(包含背景色、前景色、指令颜色)的设置
- 关于C#数据库删除数据时提示未将对象引用设置到对象的实例
- 关于POI 中单元格背景色设置(转)
- Excel2010关于设置单元格颜色和背景色的bug