在 C# 中为 dataGridView 单元格提供背景图像
我想使用 .net 组件 DataGridView 为行标题和列标题提供来自图像的自定义背景。甚至可以这样做吗?如果是这样,怎么办?
我使用 Visual Studio 2008、Windows 应用程序、C#。
I want to give the row headers and column headers a custom background from an image using the .net component DataGridView. Is it possible to even do this? And if so, how?
I use Visual Studio 2008, windows application, C#.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可以更改 datagridview 行标题的属性。您需要处理 CellPainting 或 RowPostPaint 事件并手动在行标题单元格中绘制图像。
Its possible to change the attributes of the datagridview rowheader. You'll need to either handle the CellPainting or the RowPostPaint event and manually draw the image in the row header cell.
执行此操作的方法是在 RowDataBound 事件中为每个标头元素放置一个 cssClass 名称,如下所示,并在 css 中分配背景图像。
CSS:
On way to do this is to put a cssClass name per header element in the RowDataBound event like this and assign your background image in the css.
css: