473,803 Members | 3,738 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Changing datagridview cell borders

1 New Member
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 DataGridViewTex tBoxCell, and the new class should have a property of type DataGridViewAdv ancedBorderStyl e, 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 CustomDataGridV iewCell : DataGridViewTex tBoxCell
{
private DataGridViewAdv ancedBorderStyl e _style;

public CustomDataGridV iewCell(): base()
{
_style = new DataGridViewAdv ancedBorderStyl e();
_style.Bottom = DataGridViewAdv ancedCellBorder Style.None;
_style.Top = DataGridViewAdv ancedCellBorder Style.None;
_style.Left = DataGridViewAdv ancedCellBorder Style.None;
_style.Right = DataGridViewAdv ancedCellBorder Style.None;
}

public DataGridViewAdv ancedBorderStyl e AdvancedBorderS tyle
{
get { return _style; }
set
{
_style.Bottom = value.Bottom;
_style.Top = value.Top;
_style.Left = value.Left;
_style.Right = value.Right;
}
}

protected override void PaintBorder(Gra phics graphics, Rectangle clipBounds, Rectangle bounds, DataGridViewCel lStyle cellStyle, DataGridViewAdv ancedBorderStyl e advancedBorderS tyle)
{
base.PaintBorde r(graphics, clipBounds, bounds, cellStyle, _style);
}

protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewEle mentStates cellState, object value, object formattedValue, string errorText, DataGridViewCel lStyle cellStyle, DataGridViewAdv ancedBorderStyl e advancedBorderS tyle, DataGridViewPai ntParts paintParts)
{
base.Paint(grap hics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, _style, paintParts);
}

}
Nov 25 '09 #1
0 15251

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

Similar topics

11
109622
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
2493
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 Graphics to achieve this. But with Graphics, I am not sure how I can make them diabled. Below are my codes:
2
19139
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 user clicks in the cell Regards
10
45218
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 event..., to no avail Any ideas Regards
7
9702
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 below This is what I have been trying to achieve, but when I run it ALL the cell
0
1977
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 to a DataTable. i handled the event ColumnHeaderMouseClick to perform a sort. i tryied this methods: 1/BindingSource.Sort=mydgvColumn.Name+" ASC ";
3
11934
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 the BackColors and GridColors of all of the cells, alternating row cells and selected cels. I have also sucessfully changed the BackColors of the RowHeaders and ColumnHeaders, but I can't for the life of me find out how to change the colour of the...
1
2363
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(). Is there any way to access that data type directly, since the DataSource field is null when the DataGridView is unbound? 2) Is there any way to add a row which does not have as many columns as the rest of the grid? Basically I have about 10...
0
5660
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 blank unless they are filled by the user. 2) As soon as the user enters a cell, the dtp control should appear as the editing control of that cell. If there's a value in the cell beforehand, that value is set as the value of the dtp editing control...
0
9565
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10550
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10317
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10069
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6844
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5501
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5633
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3799
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2972
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.