views:

390

answers:

2

I'm trying to save some layouts from DevExpress Grid Controls so that users can change the layouts and reload them in at a later use of the control.

My question is this for speed issues I am loading the control via a user control inside of a form. Now my problem is I am creating the control by adding an instance of the control to a panel control inside of a tabbed group control when the tab is made visible and then clearing the control when the control is hidden.

    If ClaimsGridPanelControl.Visible = True Then
            ClaimsGridPanelControl.Controls.Add(New RXClaimsGridControl(ClaimsBindingSource))
    Else
            ClaimsGridPanelControl.Controls.Clear()
    End If

So inside of the RxClaimGridControl I need to call a SaveLayout method when I am clearing the control. But there is no event, at least that I can find, that triggers when a usercontrol is removed/closed/hidden.

My thoughts for handling the .Clear() would be to raise an event in the parent control and then to handle that event inside of the user control.

Is there some event that I am missing in regards to the removal/closing/hiding of a user control, or is there a better way to do this.

+2  A: 

Override the Dispose or OnHandleDestroyed methods of the UserControl.

SLaks
Had to make a light change to the way I was clearning the forms out.Changed from the .Clear to a For Each that looped through all of the controls in the panels Controls Collection and called dispose on the controls.
msarchet
A: 

I believe you are calling the SaveLayout() from the wrong place. Layout should only be saved when changes are made to the DXGrid itself and has nothing to do with the panel.

You can achive that by handling the

GridView_ShowCustomizationForm

Sample code

  Private Sub GridView_ShowCustomizationForm(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GridView.ShowCustomizationForm
    Dim gView As DevExpress.XtraGrid.Views.Grid.GridView = CType(sender, DevExpress.XtraGrid.Views.Grid.GridView)
    AddHandler gView.CustomizationForm.FormClosing, AddressOf SaveGridSettings
End Sub

Private Sub SaveGridSettings()

 Grid.MainView.SaveLayoutToXml("c:\Settings.xml")

End Sub
Saif Khan
That would be the case if the user was using the customization form to customize the grid control. This handles the case that they have customized it in any manner, by simply dragging columns around, using a grouping method. That is however the way that I handle the saving of a normal LayoutControl, as it provides the case where the control isn't being saved every time it opens and closes.I do agree that probably using the CustomizationForm as the method to customize the grid and then only using that event would probably be a more efficient way of doing it.
msarchet
I was going based on what you said "I'm trying to save some layouts from DevExpress Grid Controls..."
Saif Khan
Yea, I didn't want to get into the actual saving of the grid layout, since that wasn't the issue, it was capturing when the UserControl was being "closed"
msarchet