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. Image for the cookie policy date
close icon

Merge Cells for virtual grid

I want to merge cells for some columns of the grid. It''s a virtual grid because of large number of records. I tried code like this.Model.Options.MergeCellsMode = GridMergeCellsMode.MergeRowsInColumn; However, it will cause performance issue. Hui

11 Replies

RT Riccardo Tarli February 12, 2006 10:16 PM UTC

I''ve noticed the same behaviour and I think the reason is the following one: even if the grid is virtual, the grid query for data cell values UNTIL the values of adiacent cells differs. This happens even if the cells are outside the displayed range. So, for example, if you have a 1.000.000 x 1.000.000 cells, all with the same value, you will find that the OnQueryCanMegeCell event is fired 1.000.000 times. Conversly, if adiacent cells have different values, no problem arise. Maybe one solution (but I''ve never tested it) is to do not merge cells - using OnQueryCanMegeCell- if the cell is not displayed. I think there is a way to know if the cell is displayed or not. Maybe engineers at Syncfusion will have a simpler solution. Hope this help. Riccardo.


HZ Hui Zhong February 14, 2006 04:21 PM UTC

Thanks Riccardo for your comment. Can any engineer at Syncfusion give us some advice on this scenario? Thanks. >I''ve noticed the same behaviour and I think the reason is the following one: even if the grid is virtual, the grid query for data cell values UNTIL the values of adiacent cells differs. This happens even if the cells are outside the displayed range. So, for example, if you have a 1.000.000 x 1.000.000 cells, all with the same value, you will find that the OnQueryCanMegeCell event is fired 1.000.000 times. Conversly, if adiacent cells have different values, no problem arise. Maybe one solution (but I''ve never tested it) is to do not merge cells - using OnQueryCanMegeCell- if the cell is not displayed. I think there is a way to know if the cell is displayed or not. Maybe engineers at Syncfusion will have a simpler solution. Hope this help. Riccardo.


AD Administrator Syncfusion Team February 14, 2006 04:30 PM UTC

Hui, normally I would not recommend using MergeCells for such large amounts. The design of it was not intented for such large amounts cells to be combined as one range. That said, one workaround here would be to force the grid not to cache any merge cell coordinates and force it to calculate the cells only just before the display is drawn and then also incorporate Riccardos suggestion with disabling the merge cells for cells that are not visible. I attached an example: Forum_40735.zip It uses MergeCellsMode = GridMergeCellsMode.BeforeDisplayCalculation and then handles private void gridControl1_QueryCanMergeCells(object sender, GridQueryCanMergeCellsEventArgs e) { int rowIndex1 = e.Style1.CellIdentity.RowIndex; int rowIndex2 = e.Style2.CellIdentity.RowIndex; if (!this.gridControl1.ViewLayout.IsRangeVisible(GridRangeInfo.Rows(rowIndex1, rowIndex2))) { e.Result = false; e.Handled = true; } } Stefan >I''ve noticed the same behaviour and I think the reason is the following one: even if the grid is virtual, the grid query for data cell values UNTIL the values of adiacent cells differs. This happens even if the cells are outside the displayed range. So, for example, if you have a 1.000.000 x 1.000.000 cells, all with the same value, you will find that the OnQueryCanMegeCell event is fired 1.000.000 times. Conversly, if adiacent cells have different values, no problem arise. Maybe one solution (but I''ve never tested it) is to do not merge cells - using OnQueryCanMegeCell- if the cell is not displayed. I think there is a way to know if the cell is displayed or not. Maybe engineers at Syncfusion will have a simpler solution. Hope this help. Riccardo.


HZ Hui Zhong February 14, 2006 09:54 PM UTC

Thanks. It works. >Hui, > >normally I would not recommend using MergeCells for such large amounts. The design of it was not intented for such large amounts cells to be combined as one range. > >That said, one workaround here would be to force the grid not to cache any merge cell coordinates and force it to calculate the cells only just before the display is drawn and then also incorporate Riccardos suggestion with disabling the merge cells for cells that are not visible. > >I attached an example: Forum_40735.zip > >It uses MergeCellsMode = GridMergeCellsMode.BeforeDisplayCalculation >and then handles > > private void gridControl1_QueryCanMergeCells(object sender, GridQueryCanMergeCellsEventArgs e) > { > int rowIndex1 = e.Style1.CellIdentity.RowIndex; > int rowIndex2 = e.Style2.CellIdentity.RowIndex; > > if (!this.gridControl1.ViewLayout.IsRangeVisible(GridRangeInfo.Rows(rowIndex1, rowIndex2))) > { > e.Result = false; > e.Handled = true; > } > } > >Stefan > > >>I''ve noticed the same behaviour and I think the reason is the following one: even if the grid is virtual, the grid query for data cell values UNTIL the values of adiacent cells differs. This happens even if the cells are outside the displayed range. So, for example, if you have a 1.000.000 x 1.000.000 cells, all with the same value, you will find that the OnQueryCanMegeCell event is fired 1.000.000 times. Conversly, if adiacent cells have different values, no problem arise. Maybe one solution (but I''ve never tested it) is to do not merge cells - using OnQueryCanMegeCell- if the cell is not displayed. I think there is a way to know if the cell is displayed or not. Maybe engineers at Syncfusion will have a simpler solution. Hope this help. Riccardo.


HZ Hui Zhong February 15, 2006 10:57 PM UTC

I have another problem now. I use the way in your example to implement the cell merge. In my project, there is some delay of showing the cell merge after the data is displayed. The worest scenario is taking 4-5 seconds to have the cell merge process done for 20 columns X 20,000 records grid. Because we only merge the visible cells, it is not supposed to take so long time to merge those cells, right? Do you have any idea on this? Hui > >Thanks. >It works. > >>Hui, >> >>normally I would not recommend using MergeCells for such large amounts. The design of it was not intented for such large amounts cells to be combined as one range. >> >>That said, one workaround here would be to force the grid not to cache any merge cell coordinates and force it to calculate the cells only just before the display is drawn and then also incorporate Riccardos suggestion with disabling the merge cells for cells that are not visible. >> >>I attached an example: Forum_40735.zip >> >>It uses MergeCellsMode = GridMergeCellsMode.BeforeDisplayCalculation >>and then handles >> >> private void gridControl1_QueryCanMergeCells(object sender, GridQueryCanMergeCellsEventArgs e) >> { >> int rowIndex1 = e.Style1.CellIdentity.RowIndex; >> int rowIndex2 = e.Style2.CellIdentity.RowIndex; >> >> if (!this.gridControl1.ViewLayout.IsRangeVisible(GridRangeInfo.Rows(rowIndex1, rowIndex2))) >> { >> e.Result = false; >> e.Handled = true; >> } >> } >> >>Stefan >> >> >>>I''ve noticed the same behaviour and I think the reason is the following one: even if the grid is virtual, the grid query for data cell values UNTIL the values of adiacent cells differs. This happens even if the cells are outside the displayed range. So, for example, if you have a 1.000.000 x 1.000.000 cells, all with the same value, you will find that the OnQueryCanMegeCell event is fired 1.000.000 times. Conversly, if adiacent cells have different values, no problem arise. Maybe one solution (but I''ve never tested it) is to do not merge cells - using OnQueryCanMegeCell- if the cell is not displayed. I think there is a way to know if the cell is displayed or not. Maybe engineers at Syncfusion will have a simpler solution. Hope this help. Riccardo.


ST stanleyj Syncfusion Team February 16, 2006 04:19 AM UTC

Hi Hui, The initial display of the merge cells does not look to take so long and while resizing, a call to invalidate or refresh does the job. Is that the initial display of the merge cells take long for you? Can you check if that is due to any further coding in the virtual grid. If you can help us to reproduce, that will help us to suggest solution. Best regards, Stanley


HZ Hui Zhong February 16, 2006 10:08 PM UTC

Thanks for your suggestion. The performance issue is resolved. However, I had another issue with your example code. Could you please run your example, and drag the scroll to the bottom of the grid, I got some indexoutofRangeException error, which was caused by the code related to the merge cells. Before I implemented merge cells, I did not get this error. Hui >Hi Hui, > >The initial display of the merge cells does not look to take so long and while resizing, a call to invalidate or refresh does the job. Is that the initial display of the merge cells take long for you? Can you check if that is due to any further coding in the virtual grid. If you can help us to reproduce, that will help us to suggest solution. > >Best regards, >Stanley


ST stanleyj Syncfusion Team February 17, 2006 09:12 AM UTC

Hi Hui, The code below ignores the message box that pops up when the current cell is in the last row, however the trace line statements will be seen in the output window. See if this helps. using Syncfusion.Windows.Forms; ExceptionManager.ExceptionCatched += new ExceptionCatchedEventHandler(ExceptionManager_ExceptionCatched); void ExceptionManager_ExceptionCatched(object sender, ExceptionCatchedEventArgs e) { ExceptionManager.ResumeCatchExceptions(); } Best regards, Stanley


HZ Hui Zhong February 17, 2006 04:55 PM UTC

Thanks >Hi Hui, > >The code below ignores the message box that pops up when the current cell is in the last row, however the trace line statements will be seen in the output window. See if this helps. > > >using Syncfusion.Windows.Forms; > >ExceptionManager.ExceptionCatched += new ExceptionCatchedEventHandler(ExceptionManager_ExceptionCatched); > > >void ExceptionManager_ExceptionCatched(object sender, ExceptionCatchedEventArgs e) >{ >ExceptionManager.ResumeCatchExceptions(); >} > > >Best regards, >Stanley


TR TrungdaicaCIT June 22, 2012 02:23 AM UTC

Hi all!

I visited your forum on the website. I find source of  "Merge Cells for virtual grid" project. But Links are Died....hic hic...So, Help me, please
Give me source of Sample: Forum_40735.zip...Admin, Help me.....
This is link on forum: http://www.syncfusion.com/support/forums/grid-windows/40735/Merge%20Cells%20for%20virtual%20grid
Thank you!


RB Ragamathulla B Syncfusion Team June 22, 2012 04:16 AM UTC

Hi TrungdaicaCIT,

 

Thank you for your interest in Syncfusion Products.

 

Answer

You can merge the cell in the grid control using “CoveredRanges.Add()” method. Using this method, we can merge the cell using range.

 

Please refer the following code snippet:

 

gridControl1.CoveredRanges.Add(GridRangeInfo.Cells(2, 5, 4, 6));

 

For that we have a sample in our dash board, please refer the sample in the following link:

 

{Installed Path}\Syncfusion\EssentialStudio\{Installed version}\Windows\ Grid.Windows\Samples\2.0\ Appearance\Covered Cell Demo

 

Please let me know if you have any concerns.

 

Regards,

Ragamathullah B.


Loader.
Live Chat Icon For mobile
Up arrow icon