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

Trying to merge cells and it does not appear to be working

Good morning. I am using the sfdatagrid in a TV Listing app, I have it filling in everything I need on the grid. But I have based it on 30 minute blocks and when a show lasts for longer than that I leave the next block or blocks empty. This works fine. After the grid is filled, I then go back through the grid and cell by cell check for blanks and if so I then try to merge the previous cell and the current cell together to form a big cell. This does not seem to work and I end up with no changes to the grid. Can you take a look at my code and let me know where the issue is? I am binding the datagrid to an itemsource, not sure if that matters.

Code:

For atoz = 1 To arrChannel.Length - 2

For atoz2 = 2 To 10

Dim recordindex

recordindex = dgStockInfo.ResolveToRecordIndex(atoz)

Dim columnindex = dgStockInfo.ResolveToGridVisibleColumnIndex(atoz2)

Dim mappingname = dgStockInfo.Columns(columnindex).MappingName

Dim record = dgStockInfo.View.Records.GetItemAt(recordindex)

Dim cellvalue = dgStockInfo.View.GetPropertyAccessProvider().GetValue(record, mappingname)

If cellvalue = "" Then

dgStockInfo.AddRange(New Syncfusion.UI.Xaml.Grid.CoveredCellInfo(atoz2 - 1, 2, atoz, 1))

End If

Next

Next

dgStockInfo.GetVisualContainer().InvalidateMeasureInfo()


Thanks for your help,

Larry


8 Replies

JN Jayaleshwari N Syncfusion Team March 4, 2016 08:18 AM UTC

Hi Larry,

Thank you for using Syncfusion Products.

We have analyzed your query “Merge cells is not working”. You can merge the range of empty cells in a row by setting the range in QueryCoveredRange which triggers in on-demand for each cell.

You can get the record, row and column index from GridQueryCoveredRangeEventArgs. You can use the GridQueryCoveredRangeEventArgs.Range  property to merge the cells like in below code snippet.

dataGrid.QueryCoveredRange += dataGrid_QueryCoveredRange;

void dataGrid _QueryCoveredRange(object sender, GridQueryCoveredRangeEventArgs e)
{

Dim mappingname = e.GridColumn.MappingName

Dim record = e.Record

Dim cellvalue = dgStockInfo.View.GetPropertyAccessProvider().GetValue(record, mappingname)

If cellvalue = "" Then

  e.Range = New Syncfusion.UI.Xaml.Grid.CoveredCellInfo(e.RowColumnIndex.ColumnIndex - 1, 2, e.RowColumnIndex.RowIndex, 1))

End If
}


Please refer the following UG link to know more about the merge cells in SfDataGrid:
http://help.syncfusion.com/wpf/sfdatagrid/merge-cells

Please let us know if this solution helps.

Regards,

Jayaleshwari N.



LM larry myers March 4, 2016 03:19 PM UTC

Thank you for your help, I have tried this page earlier, but I did not have the event tied to the grid. I have now added the event to the code and every time I try to run the code it breaks somewhere, no matter how I try to catch the error it happens, the error is "Merged Cell will not support with Single, Row, Cell, AllowFrozenGroupedHeaders False". Can you tell me how to solve this error? It seems like it is a setting I am missing or something but I cannot find it.

Thanks again for your help,
Larry


SR Sivakumar R Syncfusion Team March 4, 2016 05:09 PM UTC

Hi Lary,

Can you set SelectionUnit as Cell to solve this problem. Merge cells are not supported when SelectionUnit is Row.

Thanks,
Sivakumar


LM larry myers March 4, 2016 05:36 PM UTC

Awesome, thanks a bunch! So now the error is gone but I am still having the issue with the merged cells not looking like they are merged. I would want to have the cells take up 2 cells when the cell to the right is empty. I have attached a picture showing what I am seeing. Hopefully you can help me.

Thanks again for your help,
Larry
What I am seeing


SR Sivakumar R Syncfusion Team March 4, 2016 06:06 PM UTC

Hi Larry,

We have prepared simple sample based on your requirement. Please find the sample and code snippet from below location.
Sample:
http://www.syncfusion.com/downloads/support/forum/123289/ze/GettingStarted-918618701

Code snippet:
this.dataGrid.QueryCoveredRange += DataGrid_QueryCoveredRange;

IPropertyAccessProvider reflector = null;

private void DataGrid_QueryCoveredRange(object sender, GridQueryCoveredRangeEventArgs e)

{

    if (reflector == null)

        reflector = this.dataGrid.View.GetPropertyAccessProvider();

    if (e.Record == null)

        return;


    var colindex = this.dataGrid.Columns.IndexOf(e.GridColumn);

    if (colindex == this.dataGrid.Columns.Count - 1)

        return;


    var val = reflector.GetValue(e.Record, dataGrid.Columns[colindex + 1].MappingName);


    if (val == null || string.IsNullOrEmpty(val.ToString()))

    {

        e.Range = new CoveredCellInfo(e.RowColumnIndex.ColumnIndex, e.RowColumnIndex.ColumnIndex + 1, e.RowColumnIndex.RowIndex, e.RowColumnIndex.RowIndex);

        e.Handled = true;

    }
}




Thanks,
Sivakumar


LM larry myers March 4, 2016 06:08 PM UTC

Awesome! Thank you so very much! I will try this and will let you know how I fare.

Have a great Day!


LM larry myers March 4, 2016 06:24 PM UTC

Thank you so much for this code! After I figured out why it didn't fire, the event was untied from the grid again, it worked beautifully! 

Thanks again!


AP Ashwini Paranthaman Syncfusion Team March 7, 2016 12:00 PM UTC

Hi Larry,
We are glad that your issue has been fixed.
Please let us know if you need any assistance.
Regards,
Ashwini P.

Loader.
Live Chat Icon For mobile
Up arrow icon