We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Merge Columns in Datagrid

Thread ID:





478 Jun 28,2002 09:48 AM UTC Jun 28,2002 10:38 AM UTC WinForms 1
Tags: FAQ
Vipul Bhatt
Asked On June 28, 2002 09:48 AM UTC

Hi Clay.Another one here. Can I merge two columns in datagrid. Thanx a lot.

Clay Burch [Syncfusion]
Replied On June 28, 2002 10:38 AM UTC

It is fairly straight-forwward to make a cell blank if it has the same value as another one, but you still see the gridlines. Trying to do away with the gridlines would be difficult in a datagrid. Syncfusion's Essential Grid does allow youto cover cells so several cells behaves like a single cell. To make a DataGrid cell blank if it is the same as the one above it, you could derived a custom columnstyle and not draw the text if the value is the same as the cell above it. Here is a C# snippet that shows the Paint override that you could use. You can see how to derive a custom column style in the FAQ referenced below. public class DataGridTextMergeColumn : DataGridTextBoxColumn { protected override void Paint(System.Drawing.Graphics g, System.Drawing.Rectangle bounds, System.Windows.Forms.CurrencyManager source, int rowNum, System.Drawing.Brush backBrush, System.Drawing.Brush foreBrush, bool alignToRight) { if(rowNum > 0 && this.GetColumnValueAtRow(source, rowNum) == this.GetColumnValueAtRow(source, rowNum - 1 )) { g.FillRectangle(backBrush, bounds); return; } base.Paint(g, bounds, source, rowNum, backBrush, foreBrush, alignToRight); } } George Shepherd's Windows Forms FAQ contains an entry entitled: How can I restrict the keystrokes that will be accepted in a column of my datagrid? Check it out at: http://www.syncfusion.com/faq/winforms/search/755.asp


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon