How to cancel the window changing

2 posts, 0 answers
  1. Ellis
    Ellis avatar
    28 posts
    Member since:
    Jun 2007

    Posted 23 Jun 2010 Link to this post

       i have a problem canceling the ActiveWindowChanging events.
    When i enter in this event i check if the last ActiveWindow is updated. If not i ask user to chose to save, or not, data to db.
    If user chose to save, i update data in db, and proced changing the Active Window, as user wants. But when i save data, if i get an exception, i send a msgbox to user, and i want to "reactivate" the last ActiveWindow. In this way, the user can edit data to complete it or discard it.
    How can i cancel the window changing?
    I try with e.cancel = true, but the program loops :(
        Private Sub RadDock1_ActiveWindowChanging(ByVal sender As ObjectByVal e As Telerik.WinControls.UI.Docking.DockWindowCancelEventArgs) Handles RadDock1.ActiveWindowChanging 
            ' Salvo il Layout del tab che sto chiudendo 
            For Each c As Control In RadDock1.ActiveWindow.Controls 
                Select Case c.GetType.ToString 
                    Case "Commesse" 
                        Dim mycontrol As AnagraficaCommesse = TryCast(c, AnagraficaCommesse) 
                    Case "Articoli" 
                        Dim mycontrol As Commesse_Articoli = TryCast(c, Commesse_Articoli) 
                        If mycontrol.RadGridView1.IsInEditMode() Then 
                            If MsgBox("Un record non è stato salvato! Si desidera salvarlo ora?", MsgBoxStyle.YesNo, "Salvare i dati?") = MsgBoxResult.Yes Then 
                                Catch ex As Exception 
                                    MsgBox("Si è verificato un problema durante il salvataggio dei dati. Controllare che i dati inseriti siano corretti", MsgBoxStyle.Critical, "Errore"
                                    e.Cancel = True 
                                End Try 
                            End If 
                        End If 
                End Select 
        End Sub 

    I'm sorry if code is not clear; this is only for understand if i wrong something in it, with the e.cancel = true.

  2. Martin Vasilev
    Martin Vasilev avatar
    1061 posts

    Posted 01 Jul 2010 Link to this post

    Hi Ellis,

    Thank you for writing.

    Actually, canceling the ActiveWindowChanging event works as expected and it prevents changing the RadDock.ActiveWindow reference. The only meaningful canceling of this event is if there is a programmatically active window swapping, through a code. If active window is changed through focus change (the end user clicks on a control in a different window) then canceling that event does not make sense, because it cannot prevent focus change. For validation scenarios it will be better to use ToolWindow.Validating event instead ActiveWindowChanging.

    Martin Vasilev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. DevCraft R3 2016 release webinar banner
Back to Top