Programmatically change individual cell borders in WinForms DataGridView

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

β€œSo you can inherit the DataGridViewCell class and override the AdjustCellBorderStyle method to get a custom version of the DataGridViewCell. Then you can use this custom DataGridViewCell in your DataGridView. Note: In the custom DataGridViewCell, you must set the DataGridViewAdvancedBorderStyle so that this DataGridView's style information code can set this border style information into the cell. Then in AdjustCellBorderStyle, you need to check that the DataGridViewAdvancedBorderStyle is a public member and returns the corresponding DataGridViewAdvancedBorderStyle. Then the DataGridView PaintCells can use it to color your cell. "

I find it difficult to understand how to implement this solution. Can someone please translate the above into VB.Net working code and provide an example of calling it to change individual cell borders?

+1
winforms border cell datagridview
source share
1 answer

Here is a ready-made example that does what you need, just hidden among the additional background color settings.

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

Look for strings

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

This line draws the border of the cells, so to change the border of individual cells, change the Event Arguments (class CellBackColorEventArgs) to include any properties that you want to describe with the border. Then, in the DrawCellBackColor method, draw a border based on the passed properties (and everything you want to do in the cell)

+1
source share

All Articles