Merge Columns in Datagrid

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

1 Reply

CB Clay Burch Syncfusion Team 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

Loader.
Up arrow icon