如何更改 devexpressgrid 中选定行的颜色
我是 DevExpress 网格的新手。当选择一行时,我需要更改网格中行的颜色。
有人可以发布一些代码来实现上述场景..
提前致谢..
I am new to DevExpress grid. I need to change the color of a row in the grid when a row is selected.
Can someone please post some code to achieve the above scenario..
Thanks in advance..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果我是你,我会更改 GridView.Appearance.FocusedRow.BackColor 和 GridView.Appearance.SelectedRow.BackColor 属性。这将强制 GridControl 选择此颜色来绘制所选行的背景。
If I were you, I would change the GridView.Appearance.FocusedRow.BackColor and GridView.Appearance.SelectedRow.BackColor properties. This will force the GridControl to choose this color to paint the background of a selected row.
何时忽略此答案
如果您想让所有网格行的颜色相同(除了所选行之外),请忽略此答案,转而使用 DevExpress 的帖子。
如果您想根据每行后面的 ViewModel 中的某个变量动态为网格行着色,那么这个答案是一个很好的开始。
简而言之
SelectionState
)。添加样板后就很容易了...
不要因代码量而推迟。添加样板后,通过将其添加到项目中的任何网格来应用新的配色方案:
RowStyle="{StaticResource CustomRowStyle}"
XAML
添加此样式:
添加这些颜色:
然后附加使用
RowStyle
属性将此样式添加到网格:C#
最后,使用此转换器,如果选择或聚焦行,则需要使用该转换器对行进行不同的着色:
要连接此转换器,我们需要添加标准样板代码:
和在标题中:
When to ignore this answer
Please ignore this answer in favor of the post from DevExpress, if you want to have all grid rows colored the same (apart from the selected row).
If you want to dynamically color the grid rows based on some variable in the ViewModel behind each row, then this answer is a good start.
In a Nutshell
SelectionState
).It's easy once the boilerplate is added...
Don't be put off by the volume of code. Once you add the boiler plate, the new color scheme is applied by adding this to any grid in your project:
RowStyle="{StaticResource CustomRowStyle}"
The XAML
Add this style:
Add these colors:
Then attach this style to your grid using the
RowStyle
property:The C#
Lastly, use this converter, which is needed to color the row differently if it is selected or focused:
To hook this converter up, we need to add the standard boiler plate code:
and in the header: