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.
Unfortunately, activation email could not send to your email. Please try again.

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

Thread ID:

Created:

Updated:

Platform:

Replies:

123289 Mar 3,2016 09:38 AM Mar 7,2016 07:00 AM UWP 8
loading
Tags: SfDataGrid
larry myers
Asked On March 3, 2016 09:38 AM

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


Jayaleshwari N [Syncfusion]
Replied On March 4, 2016 03:18 AM

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.


larry myers
Replied On March 4, 2016 10:19 AM

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

Sivakumar R [Syncfusion]
Replied On March 4, 2016 12:09 PM

Hi Lary,

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

Thanks,
Sivakumar

larry myers
Replied On March 4, 2016 12:36 PM

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

Sivakumar R [Syncfusion]
Replied On March 4, 2016 01:06 PM

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

larry myers
Replied On March 4, 2016 01:08 PM

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

Have a great Day!

larry myers
Replied On March 4, 2016 01:24 PM

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!

Ashwini Paranthaman [Syncfusion]
Replied On March 7, 2016 07:00 AM

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

CONFIRMATION

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.

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.

;