Home Forums WinForms controls Xceed Grid for WinForms Exception on collapse

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #17535 |

    Hi guys,

    I’m facing the following situation: I edit a cell of a row,by entering a wrong value (which will cause the e.CancelEdit to be set to false in the cell’s ValidationError event handler, and an error message set in the cell’s LeavingEdit handler). With the cell being in edit mode, I click on the “minus” sign to collapse the detail grid containing the edited row, nothing happens, click again, an exception is raised here:

        at Xceed.Grid.CellEditorManagerCore.EndEdit(Boolean commit)
       at Xceed.Grid.Cell.LeaveEdit(Boolean commit)
       at Xceed.Grid.GroupBase.Collapse()
       at Xceed.Grid.GroupBase.set_Collapsed(Boolean value)
       at Xceed.Grid.DetailGridManager.OnClick(EventArgs e)
       at Xceed.Grid.GridControl.DoClick(EventArgs e)
       at Xceed.Grid.GridControl.OnClick(EventArgs e)

    I think I need a way to call  the CancelEdit on the current row, before the collpase action starts. But I do not know where can I put this code. The detail grid’s CollapsedChanged event is not fired yet (the exception is thrown before it is fired). I tried to override the OnCollapsedChanged on my custom derived DetailGrid but it seems the code is not reached.

     Any ideea of how to deal with this error? Thanks.

     

    Imported from legacy forums. Posted by bogdip (had 2611 views)

    User (Old forums)
    Member
    Post count: 23064

    I’m no expert here (have a pending issue myself), but I’m curious as to exactly what point you are cancelling the edit of the cell?  If you’re interested in cancelling the edit of a cell then the cell has two good places to cancel the edit: LeavingEdit & ValueChanging.  If you’re interested in cancelling the edit of the DataRow: EndingEdit.  All have event arguments that support a cancel property.  No clue why the first click isn’t doing anything though.  Those pesky first chance exceptions?

    I just poked around on what I was working with, using DataRow.EndingEdit, and collapsing the parent row does envoke the EndingEdit routine and setting cancel to true does bypass DataRow.EditEnded.  (Interesting refresh of the grid while in design mode though.)  If you want to isolate just the error you are getting you might want to look at the cell’s LeavingEdit event instead so that EndEdit of your error dump will be bypassed.

    Public Event LeavingEdit(ByVal sender As Object, ByVal e As Xceed.Grid.LeavingEditEventArgs)
         Member of: Xceed.Grid.Cell
    Summary:
    Raised after a cell has been edited to validate the content of the cell.

    Remarks:
    Custom validation can be provided in the LeavingEdit event. In this event, if the validation process fails, setting e.Cancel to true will cause the ValidationError event to be raised.  Setting e.CancelEdit to false in the ValidationError event will prevent the cell from leaving edit mode in the case where the its value fails the validation process.

    Imported from legacy forums. Posted by Hobart (had 463 views)

    User (Old forums)
    Member
    Post count: 23064

    Thanks Hobart,

         The cell edit canceling is done in cell’s LeavingEdit event handler by setting the “e.Cancel = true” and then in the cell’s ValidationError event handler I set the e.CancelEdit to false. I would expect here that the cell being prevented from leaving the edit mode, and no collapse action to occur because in the documentation it says that “Setting e.CancelEdit to false in the ValidationError event will
    prevent the cell from leaving edit mode in the case where the its value fails
    the validation process.

        But as I said, on the first click on the minus sign, nothing happen, no collapse, nor exception being thrown. On the second click on the minus sign, the debugger enters in the cell’s LeavingEdit event handler, the e.Cancel is set on true as it should, then it enters into the cell’s ValidationError event handler where e.CancellEdit is set on false. The “e.CancelEdit = false;” is the single line of code in the cell’s ValidationError event handler. The e.Exception field has the following exception set (which I suppose is the correct behavior) “The cell’s attempt to leave edit mode has been cancelled.“.

       So far, so good, the problem is that after the code exits from the cell’s ValiationError event handler,  the error with the stack trace mentioned in my first post is being thrown. The exception text is “The value of a cell or one of the cells in a DataRow failed the validation process.” and the inner exception is the same as e.Exception was in the ValidationError (“The cell’s attempt to leave edit mode has been cancelled.“).I don’t know why this inner exception is not swallowed as I think it should be and why a collapse action is allowed if the ValidationError->e.CancelEdit=false should prevent the cell from leaving the edit mode as the documentation says.

     

    Anyone can help please?

    Thanks

    Imported from legacy forums. Posted by bogdip (had 709 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi guys,

    Nobody has a clue on what’s happening in my situation or a good workaround?

     

    Thanks,

    Bogdan

    Imported from legacy forums. Posted by bogdip (had 423 views)

    User (Old forums)
    Member
    Post count: 23064

    Hello again,

    It seems there is a bug in Xceed’s code. If a detail grid collapse changing attend is performed when a cell in that detail grid is not validated, the GridValidationException which is thrown by the CellEditorManagerCore.EndEdit(boolean) is not swallowed by the Xceed code. More specifically, I think it has to be swallowed somewhere in the Collapse() method or Collapse setter.

     The MasterGrid.SelectWithMouse() method does this swallowing of this exception (that’s why when clicking somewhere else in the grid and a cell is not yet validated, this exception is not causing the app to crash), but in case of a collapse when a cell is not yet validated, this method is not called, so the GridValidationException is propagated and the app crashes.

    The workaround I found is to swallow this exception in the OnClick and OnDoubleClick methods of the parent grid control ()(the last one can cause too a collapse):

            protected override void OnClick(EventArgs e)
            {
                //if a click is performed on the +- glyph, the GridValidationException (if raised)
                //is not swallowed in Xceed code (as it should)
                try
                {
                    base.OnClick(e);
                }
                catch (GridValidationException) { }
            }

            protected override void OnDoubleClick(EventArgs e)
            {
                //if a double click on a row that produce a collapse state changing is made,
                //the GridValidationException (if raised) is not swallowed in Xceed code (as it should)
                try
                {
                    base.OnDoubleClick(e);
                }
                catch (Exception ex)
                {
                    if (!(ex is GridValidationException || ex.InnerException is GridValidationException))
                        throw;
                }
            }

    And it works, now if I try to collapse a detail grid which has a cell not yet validated (and with an error description attached), I can not, and the cell is left in edit mode, with the error icon displayed, as it should.

    Anyways, if Xceed team would have answered to this issue, they would have freed us from a lot of head aches and wasted time in “reflectoring” and studying their code to find up what’s happening.  

    Imported from legacy forums. Posted by bogdip (had 1713 views)

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.