/// <summary> /// Search through items and columns in the data table. Hide columns that, /// according to the items or column values are not needed. EX: if none of /// the items have rubrics, then hide the rubric columns and the rubric /// check box. /// </summary> private void hideUnnecessaryColumns(ref DataRow[] rptRows) { /****************************************************************************************************** * In order to answer the questions about which columns we can hide, we need to query two columns in * our datatable: * 1st - get a distinct set of values in the "QuestionType" column. Use this to decide which * Questions types are not in use so we can hide those columns. * * 2nd - Determine the Maximum value in the "MaxPoints" column. If the answer is 0, then we * know that there were no items with rubrics. If the answer is anything other than 0 * then we can hide all the rubric point columns greater than our answer. ******************************************************************************************************/ //var rptRows = rptSet.Tables[0].Rows; var questionTypes = rptRows.OfType<DataRow>().Select(r => r["QuestionType"].ToString()).Distinct(); int maxPoints = rptRows.OfType<DataRow>().Max(r => ((int)r["MaxPoints"])); // Test for presence of Mult Choice items. if (!questionTypes.Any(q => (q == "MC5" || q == "MC4" || q == "MC3"))) { foreach (int i in colAryMC) ItemAnalysisDetail_reportGrid.Columns[i].Display = false; ItemAnalysisDetail_MCToggle.Visible = false; Array.Resize(ref colAryMC, 0); } if (!questionTypes.Any(q => (q == "MC5"))) { ItemAnalysisDetail_reportGrid.Columns[colIdxE].Display = false; ItemAnalysisDetail_MCToggle.Visible = false; //Array.Resize(ref colAryMC, 0); colAryMC = colAryMC.Where(val => val != colIdxE).ToArray(); } if (!questionTypes.Any(q => (q == "MC5" || q == "MC4"))) { ItemAnalysisDetail_reportGrid.Columns[colIdxD].Display = false; ItemAnalysisDetail_MCToggle.Visible = false; //Array.Resize(ref colAryMC, 0); colAryMC = colAryMC.Where(val => val != colIdxD).ToArray(); ItemAnalysisDetail_reportGrid.Columns[colIdxE].Display = false; ItemAnalysisDetail_MCToggle.Visible = false; //Array.Resize(ref colAryMC, 0); colAryMC = colAryMC.Where(val => val != colIdxE).ToArray(); } // Test for presence of T/F items. if (!questionTypes.Any(q => (q == "T"))) { foreach (int i in colAryTF) ItemAnalysisDetail_reportGrid.Columns[i].Display = false; ItemAnalysisDetail_TFToggle.Visible = false; Array.Resize(ref colAryTF, 0); } // Test for the presence of Right/Wrong items. if (!questionTypes.Any(q => (q == "S")) //Short Answer && !questionTypes.Any(q => (q == "E"))) //Essay { foreach (int i in colAryRW) ItemAnalysisDetail_reportGrid.Columns[i].Display = false; ItemAnalysisDetail_RWToggle.Visible = false; Array.Resize(ref colAryRW, 0); } // Test for the presence of Rubric Item. if (maxPoints == 0) { foreach (int i in colAryRubric) ItemAnalysisDetail_reportGrid.Columns[i].Display = false; ItemAnalysisDetail_RubricToggle.Visible = false; Array.Resize(ref colAryRubric, 0); } else { // If Rubric Items do exist, then test for which rubric point columns to display. for (int i = colIdxPt0 + maxPoints + 1; i <= colIdxPt10; i++) ItemAnalysisDetail_reportGrid.Columns[i].Display = false; Array.Resize(ref colAryRubric, maxPoints + 2); } }