This is a migrated thread and some comments may be shown as answers.

How to cancel the window changing

1 Answer 88 Views
Dock
This is a migrated thread and some comments may be shown as answers.
Ellis
Top achievements
Rank 2
Ellis asked on 23 Jun 2010, 04:52 PM
Hi,
   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) 
                    mycontrol.SaveGridLayout() 
                Case "Articoli" 
                    Dim mycontrol As Commesse_Articoli = TryCast(c, Commesse_Articoli) 
                    mycontrol.SaveGridLayout() 
                    If mycontrol.RadGridView1.IsInEditMode() Then 
                        If MsgBox("Un record non è stato salvato! Si desidera salvarlo ora?", MsgBoxStyle.YesNo, "Salvare i dati?") = MsgBoxResult.Yes Then 
                            Try 
                                mycontrol.RadGridView1.EndEdit() 
                                mycontrol.UpdateDataSource() 
                            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 
                        Else 
                            mycontrol.RadGridView1.EndEdit() 
                        End If 
                    End If 
            End Select 
        Next 
    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.

Thanks

1 Answer, 1 is accepted

Sort by
0
Martin Vasilev
Telerik team
answered on 01 Jul 2010, 12:46 PM
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.

Regards,
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
Tags
Dock
Asked by
Ellis
Top achievements
Rank 2
Answers by
Martin Vasilev
Telerik team
Share this question
or