如何根据表值对 cxgrid 进行着色?
我希望所有存在特定字段名称“hello”的行都被着色 绿色的。我在 customdrawcell
上尝试过:
if abstable1.fieldbyname('somename').asstring = 'Hello' then
cxgrid.canvas.brush.color:=clGreen
但它不起作用......我在这里缺少什么?
I would like all rows where in particular field name 'hello' is present to get colored
green. I tried this on customdrawcell
:
if abstable1.fieldbyname('somename').asstring = 'Hello' then
cxgrid.canvas.brush.color:=clGreen
But it wont work... what am I missing here ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
对单个列或网格对象使用 OnGetContentStyle 事件。使用样式比弄乱画布要容易得多。
Use the OnGetContentStyle event for either individual columns or the grid object. Styles are much easier to work with than messing with the canvas.
您需要查看每个视图行的内部数据,而不是表中当前位置的数据。还可以使用 OnCustomDrawCell() 事件中提供的画布。
You need to look at the internal data for each view row rather that the data of the current position in the table. Also make use of the canvas provided in the OnCustomDrawCell() event.
不要尝试更改网格中的画布颜色。相反,我发现这总是是正确的--在View的OnDrawCell处理程序中更改颜色,如下例所示:
cxGrid只是视图的容器。风景是所有绘画发生的地方。
s
Don't try to change canvas colors in the Grid. Rather--and I find this to always be true--change colors in the View's OnDrawCell handler, as in this example:
The cxGrid is just a container for Views. Views are where all the painting occurs.
s
这是我的一个程序中的一些工作代码,它执行类似的操作。
grDockets 是网格,qDockets 是网格中显示的查询。根据显示的值,某些列可能会以不同的颜色绘制,并且在一种情况下 (qDocketsUrgent = 1),整行的背景颜色都会更改。
Here's some working code from a program of mine which does something similar.
grDockets is the grid, and qDockets is the query being displayed within the grid. Certain columns may be drawn in a different colour depending on the value being displayed, and in one case (qDocketsUrgent = 1), the entire line's background colour is changed.