diff --git a/PROMS/Volian.Controls.Library/DisplayLibDocs.cs b/PROMS/Volian.Controls.Library/DisplayLibDocs.cs index 352e7b5c..2bb90099 100644 --- a/PROMS/Volian.Controls.Library/DisplayLibDocs.cs +++ b/PROMS/Volian.Controls.Library/DisplayLibDocs.cs @@ -304,7 +304,28 @@ namespace Volian.Controls.Library private void btnPrint_Click(object sender, EventArgs e) { string paperSize = "Letter"; - paperSize = LibDocList[listBoxLibDocs.SelectedIndex].LibraryDocumentUsageList[0].ActiveFormat.PlantFormat.FormatData.PDFPageSize.PaperSize; // C2020-002 paper size is now set in the format files + // B2020-045: Getting Library Document usage report when no documents are selected crashes with a null reference if the first + // in libdoc usage list is null (added code that finds a non-null usage list and uses first to get format. Otherwise + // uses the default "Letter" paper size). + ItemInfo ii = null; + int sel = listBoxLibDocs.SelectedIndex < 0 ? 0 : listBoxLibDocs.SelectedIndex; + if (LibDocList[sel].LibraryDocumentUsageList == null || LibDocList[sel].LibraryDocumentUsageList.Count == 0) + { + // selected lib doc doesn't have usages, loop through to find one. Need a usage to get the active format + for (int i = 0; i0) + { + ii = LibDocList[i].LibraryDocumentUsageList[0]; + break; + } + } + } + else + ii = LibDocList[sel].LibraryDocumentUsageList[0]; + + if (ii != null) + paperSize = ii.ActiveFormat.PlantFormat.FormatData.PDFPageSize.PaperSize; // C2020-002 paper size is now set in the format files OnPrintRequest(new DisplayLibDocEventArgs("Library Document Usage", LibDocList, paperSize)); } }