Winpart from a winpart

Winpart from a winpart

Old forum URL: forums.lhotka.net/forums/t/2773.aspx


CSLABound posted on Wednesday, April 25, 2007

Using the Project Tracker example from the book, is there way to add and show a winpart to the main form (adding it to the document listing) through a different loaded winpart (instead of from the main form)?

RockfordLhotka replied on Wednesday, April 25, 2007

No, the main form has to show it so it can track the document history, etc.

But you could add a Shared/static method to the main form to allow other code to request such navigation:


Private Shared mMainForm As MainForm

Public Shared Sub DisplayWinPart(ByVal part As WinPart)

  mMainForm.ShowWinPart(part)

End Sub

Then in Form_Load or the form's constructor just make sure to set mMainForm to Me so that reference is available and all should be well.

With this addition, any child form can create a WinPart and can request that it be displayed by calling MainForm.DisplayWinPart().

 

CSLABound replied on Wednesday, April 25, 2007

Thank you so much.   I will be trying this out now.

 

Brian

CSLABound replied on Wednesday, May 23, 2007

I realize it's been a little while since I posted against this.... the code above I believe is VB, how would a person do this in C#?

Thanks again,

RockfordLhotka replied on Wednesday, May 23, 2007

Exactly the same way

private static MainForm _mainForm;

public static void DisplayWinPart(WinPart part)
{
  _mainForm.ShowWinPart(part);
}

If you find translating code from language to language difficult, I recommend Instant C# and Instant VB from Tangible. I've been using their product to convert C#->VB and VB->C# for months now, and it has made maintaining CSLA in both languages at least tolerable.

Given the number of excellent code examples floating in one language or the other, I strongly recommend that everyone at least learn to read both languages (it isn't like they are very different to start with). Failing that, something like Instant C# is an excellent alternative.

Copyright (c) Marimer LLC