Flexgrid MergedRanges add a new row

Posted by: santer.p75 on 20 July 2023, 9:58 am EST

    • Post Options:
    • Link

    Posted 20 July 2023, 9:58 am EST

    Hello,

    i have the problem when i add a Row obove the selected Row, where is set a merged range, that the new row becomes the merge range. The pointet row loose the merged range…

    I use this code

    to create a Merged Range (CustomMerge)

    grd.MergedRanges.Add(grd.GetCellRange(nRow, grd.Cols(“Col3”).Index, nRow, grd.Cols(“Col5”).Index))

    to add a new row i do this:

    grd.AddItem(“”, grd.Row)

    where the grd.row is a row with a MergedRange…

    How can i resolve this behavior?

  • Posted 21 July 2023, 6:12 am EST

    Hi,

    When defining custom merge ranges, the merge works on row/col indices, and adding a row in between a range will make the below rows lose their merged range.

    To workaround this behavior, whenever adding a row, you will need to update the current merged range as well as all the merged ranges below it. Please see the attached sample project showing a simple implementation of the same.

    Attachment: C1FlexGrid.MergeAdd.zip

    Best Regards,

    Kartik

  • Posted 22 July 2023, 4:01 am EST

    Hi,

    it doesn’t work :frowning: I have updated your example Project. I added a insert above and an insert below funktion. I have 2 cellmerges on one row. I dont know why sometimes the cellmerge row jumps up or down…

  • Posted 24 July 2023, 4:27 am EST

  • Posted 24 July 2023, 9:18 am EST

    Hi,

    Thank you for providing the updated sample project. FYI, we created the previous implementation for the update of column-merged cells. To handle the update of row-merged cells, you will need to change the code manually as per your requirement.

    We have updated the sample project you shared to handle the row-merged cells. You can refer to both code snippets and create your own implementation to handle all the cases in your project.

    Attachment: C1FlexGrid.MergeAdd.Updated.zip

    Best Regards,

    Kartik

  • Posted 28 July 2023, 9:05 am EST

    Hi,

    i am sorry to ask you another one…

    The row RemoveItem (nRow) will not delete the MergedRanges item… I try do resolve in my way but it wont work. Also move a row up or down will change the MergedRanges item…

    In my workling project the AfterEdit event some times is not triggered, so i enter text in a merged cell but i don not get a AfterEdit event…

    Thank you

    C1FlexGrid.MergeAdd.Updated.zip

  • Posted 28 July 2023, 9:06 am EST

    Hi,

    i am sorry to ask you another one…

    The row RemoveItem (nRow) will not delete the MergedRanges item… I try do resolve in my way but it wont work. Also move a row up or down will change the MergedRanges item…

    In my workling project the AfterEdit event some times is not triggered, so i enter text in a merged cell but i don not get a AfterEdit event…

    Thank you

    C1FlexGrid.MergeAdd.Updated.zip

  • Posted 31 July 2023, 6:48 am EST

    Hi,

    Your implementation to delete the MergedRanges before deleting a row is correct. The issue in your code is that you are using the Remove method of the collection inside that collection’s loop only, which is causing an exception. We have updated the sample project to delete the rows and merging correctly.

    Also, we could not observe the AfterEdit issue on our end. The AfterEdit event is fired every time a normal/merged cell is edited. If you have a different implementation in your main application, please provide a sample project or updated the attached project to reproduce the issue, so we can investigate further and assist you better. If you follow any specific steps to reproduce the issue, let us know and we will try the same on our end.

    Attachment: C1FlexGrid.MergeAdd.DeleteRanges.zip

    Best Regards,

    Kartik

  • Posted 1 August 2023, 1:22 pm EST

    Here is an exmaple project with a grid that i have integrate via copy paste.

    If you edit the cellmerge Column, only sometime the afteredit is raised. Also the move up/down will work. When i move a cellmerge row over a row that is just merged one of the row los the cell range. You can test it by moving rows up down in this project

  • Posted 1 August 2023, 1:25 pm EST

    example project…

  • Posted 2 August 2023, 2:13 am EST

  • Posted 2 August 2023, 7:29 am EST

    Hi,

    For your information,

    (1) The AfterEdit event is only fired when the edits are not canceled by the user (Esc key) or by the Grid internally.

    (2) In the case of editing merged cells, the same value is set to all the individual cells as well.

    Since you now have knowledge of the information stated above, in your project, you have merged string and boolean DataType cells and when they are edited, the same string value is set to both the cells. But since the boolean cells cannot accept string values, the edit is canceled by the Grid internally, and the AfterEdit event is not fired. This is the correct behavior of the C1FlexGrid.

    To workaround this, since you are assigning the Frozen style to the merged cells, you can create a copy of the Frozen style instead and set its DataType to string. Then, you can assign this style to your merged cells which will make all these cells of string type.

    Also, the row MoveUp and MoveDown are working fine on our end. Please see the attached video for reference.

    Attachment: row move up-down.zip , C1FlexGrid.MergeAdd.AfterEdit.zip

    Thanks, and Best Regards,

    Kartik

  • Posted 3 August 2023, 2:56 am EST

    Hi,thank you!

    here is a screen caputre where you can see that the mergedcell loos when moving up/down after a couple of moves. I have change the border color to black so you can see betterC1FlexGrid.MergeAdd.AfterEdit 03-08-2023.zipForm1.zip

  • Posted 4 August 2023, 1:39 am EST

    Hi,

    This behavior is observed when 2 merged rows are moved over each other. For this scenario, we have updated the up-down move logic. Please refer to the updated project for reference.

    C1FlexGrid.MergeAdd.UpdatedUpDownMove.zip

    Best Regards,

    Kartik

  • Posted 7 August 2023, 6:37 am EST

    Hi, on delete its necesari to reorganice the cellrange above the delete row…

    This is my code, i think now it works…

    Dim removableMerges = New List(Of C1.Win.C1FlexGrid.CellRange)
    Dim row = grd.Row + 1
    
    For index = 0 To grd.MergedRanges.Count - 1
      Dim mergedRange = grd.MergedRanges(index)
    
      If grd.Row = mergedRange.r1 Then
        removableMerges.Add(mergedRange)
      End If
    Next
    removableMerges.ForEach(Sub(range) grd.MergedRanges.Remove(range))
    
    grd.RemoveItem(grd.Row)
    
    
    For index = 0 To grd.MergedRanges.Count - 1
    
      Dim range = grd.MergedRanges(index)
    
      If range.r1 = range.r2 Then
    
        If range.r1 < row Then
          Continue For
        ElseIf range.r1 >= row Then
          range.r1 -= 1
          range.r2 -= 1
          grd.MergedRanges.RemoveAt(index)
          grd.MergedRanges.Insert(index, range)
        End If
    
      End If
    
    Next
    
  • Posted 7 August 2023, 7:51 am EST

    Hi,

    We are happy to know that you were able to update the code to work as per your implementation. Let us know if you still face any issues.

    Best Regards,

    Kartik

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels