Code Not Displaying Sumary Property

  • Thread starter Thread starter reigh7
  • Start date Start date
R

reigh7

Guest
I'm posting this here because I think fundamentally the problem(s) lay in my code not in screen design or data design. I'm following a tutorial I have in past from Andy Kung to create a list box mover screen for a many to many relationship combining table. The original article is gone but the archive of it can be found at archive.org in the wayback machine The Dec 11 2011 entry here https://web.archive.org/web/2011121...te-a-many-to-many-relationship-andy-kung.aspx .

Fist of all there are two parts that require a little code the first part is defining a summary property as recommended by the article which is covered in a separate article by Beth Massi Getting the Most out of LightSwitch Summary Properties. Both Articles at written in VB as the platform Lightswitch was designed for both VB and C# articles so I have to convert the code to C# see below.

The Andy Kung article simple defines the summary property code on the application side the way Lightswitch does with a calculated field the runs on that side. The calculated field code they use looked like this and I've done my best to define the code in C# as follows below two versions because the second version was to try and handle nulls when adding or removing entries.


Private Sub Summary_Compute(ByRef result As String)
result = Genre.Name
End Sub

partial void PanelParts_Compute(ref string result)
{
result = LabPart.LabPartFullName;
}

partial void PanelParts_Compute(ref string result)
{
if (LabPart == null)
{
result = LabPart.LabPartFullName ?? "None Listed";
}
if (LabPart.LabPartFullName != null)
result = LabPart.LabPartFullName;
}
The problem here is that on the screen while it appears the rest of the instructions to setup two columns below the details of a selected entry in the parent entity to show a list control of both the associated children properties set to the parent entity, and a second list of all of the possible Lab Parts currently available. The Available Lab Parts show up in the list but when I use the buttons coded to add Lab Parts to a panel they do not show up in the other list and blindly hitting delete on the empty rows throws the null exception to indicate there is nothing to remove. In this case I'm assembling Lab Panels from their Lab Parts the screen looks like the following with a third column in the middle for the add remove buttons. I will show the original VB code and the C# sharp code I'm have as well to define the buttons methods of action.

Nothing shows up in here when a Lab Panel is selected or a Lab Part is added to that Lab Panel with the buttons defined in code. Not even a sort header shows up for this list control like it does for the available Lab Parts list next to this one.

1374930.png

This is the VB code example for the many to many screen buttons for movie genres and the code I've modified to work for a C# screen for assembling Lab Panels with Lab Parts.

Private Sub AddGenre_Execute()
If (Genres.SelectedItem IsNot Nothing) Then
Dim mg As MovieGenre = MovieGenres.AddNew()
mg.Movie = Me.MovieProperty
mg.Genre = Genres.SelectedItem
End If
End Sub

Private Sub RemoveGenre_Execute()
MovieGenres.DeleteSelected()
End Sub


partial void AddLabPart_Execute()
{
if (LabPanelAssembledParts.SelectedItem != null)
{
bool LabPartExists = false;
foreach (LabPanelAssembledPart mgSearch in this.LabPanelAssembledParts)
{
if (mgSearch.LabPart.LabPartFullName == this.LabPart.SelectedItem.LabPartFullName)
{
LabPartExists = true;
}
}

if (LabPartExists == true)
{
ScreenExtensions.ShowMessageBox(this, "'Lab Panel Part' already exists");
}
else
{
LabPanelAssembledPart lpap = LabPanelAssembledParts.AddNew();
lpap.LabPanel = this.LabPanelProperty;
lpap.LabPart = LabPart.SelectedItem;
}
}
}

partial void RemoveLabPart_Execute()
{
LabPanelAssembledParts.DeleteSelected();
}

I'm pretty sure the problem again is somehow related to the code not building the screens as all of the instructions for this example are straight forward otherwise.

Continue reading...
 
Back
Top