DataGridView 选中一行后,保持前景色(颜色,字体)不变
最近在做项目的时候,发现了一个问题,就是当DataGridView选中一行的时候,选中中的颜色均变为DefaultCellStyle中的SelectionForeColor。但是问题是,我已经根据该行不同的数据(规则或者状态)显示了不同的颜色(例如股票行情信息)。显然,编程Highlight颜色是不对的。那么如何保持原来的颜色呢。查了好多论坛都没有找到,最后终于自己解决了问题。
( Recently, I met a problem while doing the project. When I select one row in DataGridView control, the ForeColor of the selection row was changed to the DefaultCellStyle SelectionForeColor. Obviously, It's not what I want. The reall situation is I already format the cell to diference color according to the data(Such as stock information). How to solve this? Find the solution as following: )
解决方法如下:
Solution as follows:
给DataGridView添加CellFormatting事件,把ForeColor重新付给当前正在Format的Cell。
Add CellFormatting event to DataGridView:
private void dgMarketInfo_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
e.CellStyle.SelectionForeColor = e.CellStyle.ForeColor;
}
DataGridView 选中一行后,保持前景色(颜色,字体)不变相关推荐
- DataGridView 选中一行不变色
private void textGridView_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e){e.Cel ...
- element table 表格合并及如何默认选中合并后的第一行
1. 合并效果及代码如下: 1.表格头 2.js 合并前的每一个小行都会执行一此下面这个代码,如上图所示,执行第一行时合并,执行到第二行设置合并行数为0 就可以了 objectSpanMethod({ ...
- C#中datagridview选中行后textbox显示选中的内容
我想让datagridview中某一行被选中时,textbox中显示选中的值,datagridview的选中模式是整行: this.dataGridView1.SelectionMode = Data ...
- SAP Spartacus元素被选中后,focus颜色的css实现
如下图,当按下tab键,让Spartacus元素处于被选中状态后,显示的蓝色border: 这个border的颜色通过变量–cx-color-visual-focus定义: 我们点击storefron ...
- DataGridview单击某个单元格选中一行
DataGridview如何单击某个单元格选中一行? 代码的方式设置 this.dataGridView1.SelectionMode = DataGridViewSelectionMode.Full ...
- linux终端有颜色字体
linux终端有颜色字体 Linux下Shell脚本输出带颜色文字 脚本输出带颜色文字脚本输出带颜色文字 脚本输出带颜色文字 文本终端的颜色可以使用"ANSI非常规字符序列"来生成 ...
- Android 3 使用 smartTable 表格工具 实现选中一行 并获得行所有信息
Android 使用 smartTable 表格工具 实现选中一行 并获得行所有信息 强力推荐一款 android 自动生成表格框架 smartTable,它有着非常强大的功能,而且日趋完善,能实现很 ...
- android中设置ListView的选中的Item的背景颜色(附源码)
http://longyi-java.iteye.com/blog/976067 ListView中没有默认的选择颜色,只有选择Item后的焦点颜色,鼠标点击时Item有颜色,放开鼠标后颜色也就没有了 ...
- tableView 删除一行后下一行点击事件被忽略
[转]- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:( ...
最新文章
- Redis从入门到精通,至少要看看这篇!
- 1.13 编程基础之综合应用 47 大整数除法方法 python
- leetcode - 121.买卖股票的最佳时机
- P1640 [SCOI2010]连续攻击游戏
- rabbitmq3.7.3 发布了一个新的 exchange x-random
- TCP/IP长连接和短连接
- 案例:如何解决难以重现的BUG
- 华为OLT快速配置指南
- python爬虫之模拟登陆(CSDN篇)
- # 书籍《银河帝国10—裸阳》读后感—20210606
- AUC(ROC曲线下方的面积大小)
- Apache日志分割及分析
- java 导出excel 附带图片
- UE4-地形植被自动分布方法
- js设置弹出式独立窗口页面,和 window 的方法
- 实验七 3 小希练打字
- javascript运动框架(三)
- 斐波那契数列(前30)Python
- 智能门锁:电源管理概述2
- 520 送女朋友礼物大全 (推荐男生收藏)