From f79ff651a569dc2a0a67040fda5be25245e954b3 Mon Sep 17 00:00:00 2001 From: Kathy Date: Mon, 18 Jan 2021 17:05:08 +0000 Subject: [PATCH] =?UTF-8?q?B2021-003:=20Incoming=20transitions:=20random?= =?UTF-8?q?=20Enable/disable=20of=20=E2=80=98Convert=20Selected=20Text?= =?UTF-8?q?=E2=80=99=20button=20&=20crashing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DisplaySearch.Designer.cs | 5 ++- .../Volian.Controls.Library/DisplaySearch.cs | 41 +++++++++++++------ 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/PROMS/Volian.Controls.Library/DisplaySearch.Designer.cs b/PROMS/Volian.Controls.Library/DisplaySearch.Designer.cs index ba50e946..03fa3004 100644 --- a/PROMS/Volian.Controls.Library/DisplaySearch.Designer.cs +++ b/PROMS/Volian.Controls.Library/DisplaySearch.Designer.cs @@ -1335,6 +1335,7 @@ namespace Volian.Controls.Library this.lbSrchResultsIncTrans.SelectedIndexChanged += new System.EventHandler(this.lbSrchResults_SelectedValueChanged); this.lbSrchResultsIncTrans.ItemClick += new System.EventHandler(this.lbSrchResultsIncTrans_ItemClicked); this.lbSrchResultsIncTrans.MouseMove += new System.Windows.Forms.MouseEventHandler(this.lbSrchResults_MouseMove); + this.lbSrchResultsIncTrans.ItemCheck += this.lbSrchResultsIncTrans_ItemChecked; // // panSearchButtons // @@ -1687,9 +1688,9 @@ namespace Volian.Controls.Library } - #endregion + #endregion - private DevComponents.DotNetBar.TabControl tabSearchTypes; + private DevComponents.DotNetBar.TabControl tabSearchTypes; private DevComponents.DotNetBar.TabControlPanel tabControlPanel2; private DevComponents.DotNetBar.TabControlPanel tabControlPanel5; private DevComponents.DotNetBar.TabItem tabROSearch; diff --git a/PROMS/Volian.Controls.Library/DisplaySearch.cs b/PROMS/Volian.Controls.Library/DisplaySearch.cs index 71817b05..c2d311b2 100644 --- a/PROMS/Volian.Controls.Library/DisplaySearch.cs +++ b/PROMS/Volian.Controls.Library/DisplaySearch.cs @@ -1171,6 +1171,19 @@ namespace Volian.Controls.Library LastResultsMouseOverIndex = ResultsMouseOverIndex; } } + // B2021-003: random crash on lbSrchResultsIncTrans selection. Originally, only ItemClicked was used + // to track how many items in the list were checked. However, this gets called for both + // the clicked & checked events, so the count of checked items was not accurate (this count, + // IncTransSelectedCount was incremented/decremented when event occurred). The reason that the clicked + // event needs to be used is that the sender contains the bound item (proms item) but the checked + // event does not, so both are needed. The tracking of checked items is done to enable/disable + // the 'Convert Selected to Text' button. The fix was to flag from the ItemChecked event that the + // item was checked not just selected, so that the code in Clicked only runs for a check event. + private bool didcheck = false; + private void lbSrchResultsIncTrans_ItemChecked(object sender, EventArgs e) + { + didcheck = true; + } // C2020-033: lbSrchResultsIncTrans_ItemClicked is used to check permissions of a selection before allowing an // item to be clicked and to turn on/off the btnTranCvtSelToTxt button for converting selected to test. // Two variables are used to keep track if items are checked in the list box: @@ -1183,23 +1196,27 @@ namespace Volian.Controls.Library private void lbSrchResultsIncTrans_ItemClicked(object sender, EventArgs e) { ListBoxItem lbi = sender as ListBoxItem; - ItemBindingData ibd = lbi.Tag as ItemBindingData; - ItemInfo ii = ibd.DataItem as ItemInfo; - bool allowNonAdmin = IncTranCvtPerm(); - if (lbi.CheckState == CheckState.Checked && ii != null) + if (didcheck && lbi != null) { - if (!allowNonAdmin && !UserInfo.CanEdit(MyUserInfo, ii.MyDocVersion)) + ItemBindingData ibd = lbi.Tag as ItemBindingData; + ItemInfo ii = ibd.DataItem as ItemInfo; + bool allowNonAdmin = IncTranCvtPerm(); + if (lbi.CheckState == CheckState.Checked && ii != null) { - FlexibleMessageBox.Show("You do not have permission to edit the procedure, section, or step.", - "Convert Transition to Text", MessageBoxButtons.OK, MessageBoxIcon.Information); - lbi.CheckState = CheckState.Unchecked; + if (!allowNonAdmin && !UserInfo.CanEdit(MyUserInfo, ii.MyDocVersion)) + { + FlexibleMessageBox.Show("You do not have permission to edit the procedure, section, or step.", + "Convert Transition to Text", MessageBoxButtons.OK, MessageBoxIcon.Information); + lbi.CheckState = CheckState.Unchecked; + } + else + if (!JustDidSelection) IncTransSelectedCount++; } else - if (!JustDidSelection) IncTransSelectedCount++; + if (!JustDidSelection && IncTransSelectedCount > 0) IncTransSelectedCount--; // user unchecked an item + if (!JustDidSelection) btnTranCvtSelToTxt.Enabled = IncTransSelectedCount > 0; } - else - if (!JustDidSelection && IncTransSelectedCount > 0) IncTransSelectedCount--; // user unchecked an item - if (!JustDidSelection) btnTranCvtSelToTxt.Enabled = IncTransSelectedCount > 0; + didcheck = false; JustDidSelection = false; } private bool _ProcessingSelectedValueChanged = false;