Hello,
if you present SubDialog in context of MainDialog, (the method PresentDialog() is invoked in scope of MainDialog) then the SubDialog can access MainDialog via its own Owner variable. For example:
// Being in a sub dialog assume the owner is the searched dialog
var Application::MainDialog mainDialog = (Application::MainDialog)Owner;
// Found?
if ( mainDialog != null )
{
...
}
If there is no direct relationship between the both dialogs, you can e.g. use a variable in SubDialog to refer to the MainDialog. Just in the momenent when you create or present the SubDialog, initialize the variable with a a reference to MainDialog:
// Create a new instance of the sub dialog.
var Application::SubDialog subDialog = new Application::SubDialog;
// The known instance of the previously opened main dialog.
var Application::MainDialog mainDialog = ...;
// Let the sub dialog store a reference to the main dialog. In this
// manner the sub dialog can access the main dialog
subDialog.YourVariable = mainDialog;
// Present the sub dialog in context of e.g.the application's root object:
GetRoot().PresentDialog( subDialog, ... );
Then when SubDialog wants to access functionality from MainDialog, do this via the variable. Please see also Implementing component interface.
If there is no direct relationship between the both dialogs, you can use the method FindDialogByClass() and search the entire tree of dialogs for the particular one. See also the section Enumerate and search for existing Dialogs. For example:
// Being in a sub dialog search for the main dialog (if any)
var Application::MainDialog mainDialog =
(Application::MainDialog)GetRoot().FindDialogByClass( Application::MainDialog );
// Found?
if ( mainDialog != null )
{
...
}
Best regards
Paul Banach