B2021-003: Incoming transitions: random Enable/disable of ‘Convert Selected Text’ button & crashing

This commit is contained in:
Kathy Ruffing 2021-01-18 17:05:08 +00:00
parent 8ddf84e0bc
commit f79ff651a5
2 changed files with 32 additions and 14 deletions

View File

@ -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
//

View File

@ -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,6 +1196,8 @@ namespace Volian.Controls.Library
private void lbSrchResultsIncTrans_ItemClicked(object sender, EventArgs e)
{
ListBoxItem lbi = sender as ListBoxItem;
if (didcheck && lbi != null)
{
ItemBindingData ibd = lbi.Tag as ItemBindingData;
ItemInfo ii = ibd.DataItem as ItemInfo;
bool allowNonAdmin = IncTranCvtPerm();
@ -1200,6 +1215,8 @@ namespace Volian.Controls.Library
else
if (!JustDidSelection && IncTransSelectedCount > 0) IncTransSelectedCount--; // user unchecked an item
if (!JustDidSelection) btnTranCvtSelToTxt.Enabled = IncTransSelectedCount > 0;
}
didcheck = false;
JustDidSelection = false;
}
private bool _ProcessingSelectedValueChanged = false;