最近在做项目的时候,发现了一个问题,就是当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 选中一行源码
完全是源码,可以很好地解决C# Winform中对DataGridView 进行排序后,行的颜色,单元格颜色改变了的方法: 在赋数据源时:把 DataGridView1.DataSource=DataTable1,去掉,用我提供的源码的方法,再数据源就可以了: 改成...
直接在datagridview中删除选中行
将datagridview的选中部分导出到EXCEL,可跳行选中,将选中的数据导出到表格中,方便快捷,源码已在VS2013中测试成功
winform DataGridView控件 实现右击选中行,右击首列弹窗增删行
C#中DataGridview某行选中变黑,可以点击此行任意列,都可触发事件
C# windows datagridview表格行上下拖动示例 一个简单的示例代码 具体可以根据需求自行修改
在进行DataGridView添加修改删除时,分两种情况进行锁定显示。锁定时,添加锁定添加行显示,修改锁定修改后的行显示,删除按情况锁定行显示。
c# datagridview 经典行拖拽
主要介绍了C#中改变DataGridView控件边框颜色的方法,默认的DataGridView边框颜色很丑,本文用编程方法实现修改DataGridView边框颜色,需要的朋友可以参考下
winform DataGridView 合计 行 控件 winform DataGridView 合计 行 控件
实现DataGridView最后一行统计作用
4. DataGridView判断当前选中行是否为新追加的行 5. DataGridView删除行可否设定 6. DataGridView行列不表示和删除 7. DataGridView行列宽度高度设置为不能编辑 8. DataGridView行高列幅自动调整 9. DataGridView...
4. DataGridView判断当前选中行是否为新追加的行 5. DataGridView删除行可否设定 6. DataGridView行列不表示和删除 DataGridView控件用法合集(二) 7. DataGridView行列宽度高度设置为不能编辑 8. DataGridView...
c# 中datagridView中删除行的经典操作
通过鼠标移动实时选中DataGridView中的对应行的C#源代码,分享给大家
主要介绍了C# 实现dataGridView选中一行右键出现菜单,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
DataGridView添加合计行,汇总行
c# datagridview 行合计 在最底行增加合计,合计行不会随滚动条拉动而移动