Back to Devexpress

BaseView.QueryDocument Event

windowsforms-devexpress-dot-xtrabars-dot-docking2010-dot-views-dot-baseview-a5398f48.md

latest5.0 KB
Original Source

BaseView.QueryDocument Event

Occurs when the restored layout version has a Document that is not present in the View. Allows you to skip this Document or add it to the View.

Namespace : DevExpress.XtraBars.Docking2010.Views

Assembly : DevExpress.XtraBars.v25.2.dll

NuGet Package : DevExpress.Win.Navigation

Declaration

csharp
public event QueryDocumentEventHandler QueryDocument
vb
Public Event QueryDocument As QueryDocumentEventHandler

Event Data

The QueryDocument event's data class is QueryDocumentEventArgs. The following properties provide information specific to this event:

PropertyDescription
CancelGets or sets whether the Document that triggered the QueryDocument event should be restored.
CaptionGets or sets the new caption of the restored Document.
ControlGets or sets the control hosted by this Document.
NameReturns the BaseDocument.ControlName property value of this Document.

Remarks

You can save and load Document layouts with the View’s SaveLayoutTo... / RestoreLayoutFrom... methods (for example, SaveLayoutToXml and RestoreLayoutFromXml). If a restored layout contains Documents that are not present in the current View, these Documents re-appear and the QueryControl event fires to supply these Documents with content. Document captions are not stored as a part of a layout and are omitted from restored Documents. To set captions for restored Documents, handle the QueryDocument event. Use the e.Name property to identify a Document that triggered this event (this property returns the Document’s ControlName property value).

csharp
void OnQueryDocument(object sender, QueryDocumentEventArgs e) {
    if (e.Name == "document1ControlName")
        e.Caption = "document1_Restored";
}

void OnQueryControl(object sender, QueryControlEventArgs e) {
    if (e.Document == document1)
        e.Control = new userControl1();
}
vb
Private Sub OnQueryDocument(ByVal sender As Object, ByVal e As QueryDocumentEventArgs)
    If e.Name = "document1ControlName" Then
        e.Caption = "document1_Restored"
    End If
End Sub

Private Sub OnQueryControl(ByVal sender As Object, ByVal e As QueryControlEventArgs)
    If e.Document = document1 Then
        e.Control = New userControl1()
    End If
End Sub

If you do not want the QueryControl event to supply content for restored Documents, assign controls to the e.Control property of the QueryDocument event.

csharp
void OnQueryDocument(object sender, QueryDocumentEventArgs e) {
    if (e.Name == "document1ControlName") {
        e.Caption = "document1_Restored";
        e.Control = new userControlPropertiesPanel();
    }
}
vb
Private Sub OnQueryDocument(ByVal sender As Object, ByVal e As QueryDocumentEventArgs)
    If e.Name = "document1ControlName" Then
        e.Caption = "document1_Restored"
        e.Control = New userControlPropertiesPanel()
    End If
End Sub

To skip a Document and not restore it, enable the e.Cancel property.

csharp
void OnQueryDocument(object sender, QueryDocumentEventArgs e) {
    if (e.Name == "document2ControlName")
        e.Cancel = true;
}
vb
Private Sub OnQueryDocument(ByVal sender As Object, ByVal e As QueryDocumentEventArgs)
    If e.Name = "document2ControlName" Then
        e.Cancel = True
    End If
End Sub

See Also

BaseView Class

BaseView Members

DevExpress.XtraBars.Docking2010.Views Namespace