473,320 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,320 developers and data experts.

Changing datagridview cell borders

1
Hi,

I searched a lot about changing the DataGridView cell borders. BYTES helped me so I will write down the solution:

1. You should override the class DataGridViewTextBoxCell, and the new class should have a property of type DataGridViewAdvancedBorderStyle, this property you will change from the outside:

2. You will override also the PaintBorder, and Paint methods in a way that they will get the new property instead of the default one.

3. Thats it, all you have to do is to use your own overriden cell class for adding new cells in the rows.

-------------------------------------
here is the overriden class:
class CustomDataGridViewCell : DataGridViewTextBoxCell
{
private DataGridViewAdvancedBorderStyle _style;

public CustomDataGridViewCell(): base()
{
_style = new DataGridViewAdvancedBorderStyle();
_style.Bottom = DataGridViewAdvancedCellBorderStyle.None;
_style.Top = DataGridViewAdvancedCellBorderStyle.None;
_style.Left = DataGridViewAdvancedCellBorderStyle.None;
_style.Right = DataGridViewAdvancedCellBorderStyle.None;
}

public DataGridViewAdvancedBorderStyle AdvancedBorderStyle
{
get { return _style; }
set
{
_style.Bottom = value.Bottom;
_style.Top = value.Top;
_style.Left = value.Left;
_style.Right = value.Right;
}
}

protected override void PaintBorder(Graphics graphics, Rectangle clipBounds, Rectangle bounds, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle)
{
base.PaintBorder(graphics, clipBounds, bounds, cellStyle, _style);
}

protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
{
base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, _style, paintParts);
}

}
Nov 25 '09 #1
0 15165

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: dgk | last post by:
Is there a way to change the foreground or background color of a single cell in an unbound datagridview?
0
by: sunny076 | last post by:
Hi, I am having difficulties creating a derived class for DisabledDataGridViewTextBoxColumn and cell when the VisualStyle is not supported. Basically I am down to either using ControlPaint or...
2
by: steve | last post by:
Hi All How do I get the screen coordinates of the selected cell boundaries in a datagridview I need to position a form at the top left position of the selected cell regardless of where the...
10
by: steve | last post by:
Hi All I would like to be able to change the cell borders on certain cells to none at runtime to make a group of cells appear to be merged I have tried the following in the cellformatting...
7
by: steve | last post by:
Hi All I urgently need help on setting datagridview cell borders at runtime I found some code on the web from Programming Smart Client Data Applications with .NET 2.0 by Brian Noyes See...
0
by: Hassan | last post by:
Hi, Im using visual studio 2005,C#2 Framework 2.0 In my program, i have a DataGridView where DataGridView.DataSource equal to a BindingSource.DataSource and this BindingSource.DataSource equalt...
3
by: sheridan | last post by:
Hi everyone. I'm hoping somone can help me, because I've been stuck on this all evening and haven't found the answer online yet. I have a DataGridView control and have managed to change all of...
1
by: stumorgan | last post by:
I have a couple questions regarding the DataGridView object... 1) What is the underlying data type that the DataGridView uses if you are using it unbound and do for instance dgv.Columns.Add(). ...
0
by: priyamtheone | last post by:
I'm trying to make a datagridview column to act like a datetimepicker column (C#.Net 2005). These are the behaviours that the dgv should have: 1) Initially all the cells of the dtp column should be...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.