以编程方式更改WinForms DataGridView中的单个单元格边框 [英] Programmatically Change Individual Cell Borders in a WinForms DataGridView

查看:198
本文介绍了以编程方式更改WinForms DataGridView中的单个单元格边框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要以编程方式更改WinForms DataGridView中单个单元格的边框。当在网上搜索时,我发现这个链接( http://bytes.com/groups/net-vb/501128-changing-datagridview-cell-borders-runtime )这是我试图做的一样的事情;但是,没有解决方案的代码示例,这是

I need to programmatically change the border of individual cells in a WinForms DataGridView. When searching on the 'net, I found this link (http://bytes.com/groups/net-vb/501128-changing-datagridview-cell-borders-runtime) which is the same thing that I am trying to do; however, there isn't a code example there of the solution, which is

所以你可以继承
DataGridViewCell类,并覆盖AdjustCellBorderStyle方法来获取一个
定制版本的DataGridViewCell然后你可以使用这个自定义的
DataGridViewCell在您的DataGridView
注意:
在您定制的DataGridViewCell,你应该公开一个
DataGridViewAdvancedBorderStyle public成员使DataGridView代码可以
将此成员边框样式信息设置到单元格,然后在
AdjustCellBorderStyle实现中,您应该检查这个
DataGridViewAdvancedBorderStyle的公共成员并返回相应的
DataGridViewAdvancedBorderStyle然后,DataGridView PaintCells可以使用它来
绘制您的单元格。。

"So you can inherit from the DataGridViewCell class and overrides AdjustCellBorderStyle method to get a customized version of DataGridViewCell. Then you can use this customized DataGridViewCell in your DataGridView. Note: In your customized DataGridViewCell, you should expose a DataGridViewAdvancedBorderStyle public member so that DataGridView code can set this member border style information to the cell. Then in the AdjustCellBorderStyle implementation, you should check the this DataGridViewAdvancedBorderStyle public member and return corresponding DataGridViewAdvancedBorderStyle. Then DataGridView PaintCells can use it to paint your cell.".

我很难理解实现此解决方案。有人可以将以上内容翻译成正常的VB.Net代码,并提供一个调用它来更改单个单元格边框的示例?

I'm having a hard time understanding implementing this solution. Could someone please translate the above into working VB.Net code and provide an example of calling it to change an individual cell's borders?

推荐答案

这是一个现成的例子,可以做你所需要的,只是隐藏在设置背景颜色的额外功能之间。

Here is a ready made example which does what you need, just hidden amongst the extra functionality of setting the background colour.

http://www.codeproject.com/KB/grid/hulihui_CustomDataGridVie.aspx

寻找线条

// must draw border for grid scrolling horizontally 
e.Graphics.DrawRectangle(gridPenColor, rect1);  

该行绘制单元格边框,因此更改单个单元格边框可以更改Event args(CellBackColorEventArgs类)来包括你想要描述边界的任何属性。然后在DrawCellBackColor方法中,根据属性(以及要在单元格中绘制的任何其他内容)绘制边框。

That line draws a cells border, so to change an individual cells border change the Event args (CellBackColorEventArgs class) to include whatever properties you want to describe the border. Then in the DrawCellBackColor method draw the border based on these passed in properties (and whatever else you want to draw in the cell)

这篇关于以编程方式更改WinForms DataGridView中的单个单元格边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆