数据绑定后如何为datagridview中的每一行设置渐变颜色
我想在数据绑定后为 datagridview 中的每一行设置渐变颜色(我的意思是在 DataBoundCompleted 事件中)
我看到这篇文章,但所有这些都是用于选择一行。我想为每一行设置渐变。
DataGridView,为每个DataGridView添加唯一的渐变行
如何:自定义Windows 窗体 DataGridView 控件中行的外观
谢谢
I want to set a gradient color for each row in datagridview after data binding(I mean in DataBoundCompleted event)
I see this Articles but all of them are for selecting a row.I want set gradient for each rows.
DataGridView, add unique gradient to each Row
How to: Customize the Appearance of Rows in the Windows Forms DataGridView Control
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您链接到的第二个示例正是您需要的。触发 DataGridView.RowPrePaint 事件对于网格内的每一行。
此事件的文档页面上的示例仅自定义呈现所选行,因为它包含以下检查。
删除此检查,您将看到每一行都有自定义背景。
The second example you link to is exactly the one you need. The DataGridView.RowPrePaint event is fired for every row within the grid.
The example on the documentation page for this event only custom-renders the selected row, because it includes the following check.
Remove this check an you will see every row has a custom background.
我不知道这是否能很好地帮助那些在谷歌搜索后登陆这里的人,我基于我在另一个论坛中找到的一些vb代码:
一旦你将其构建为一个单独的类,它就会显示在你的(VS2010)工具箱中并且您将其放在表单上...
此代码适用于整个数据网格视图,因此要对每一行执行此操作,您可以使用 RowPrePaint 事件...
I don't know if this well help someone who lands here after a Google search, I based this on some vb code I found in another forum:
once you have built this as a seperate class it shows up in your (VS2010) toolbox and you drop it on your form ...
This code works for the entire datagrid view so to do it for each row, you can use the RowPrePaint event...