diff --git a/PROMS/Volian.Controls.Library/ListBoxMulti.cs b/PROMS/Volian.Controls.Library/ListBoxMulti.cs index 51582552..74acaa54 100644 --- a/PROMS/Volian.Controls.Library/ListBoxMulti.cs +++ b/PROMS/Volian.Controls.Library/ListBoxMulti.cs @@ -7,6 +7,8 @@ using System.Windows.Forms; namespace Volian.Controls.Library { + //Class to handle bug in Windows WinForms ListBox + // that autoselects first item when no items are selected public partial class ListBoxMulti : ListBox { public ListBoxMulti() @@ -19,8 +21,13 @@ namespace Volian.Controls.Library Disposed += ListBoxMulti_Disposed; } + //singleselectedindex + // will help to fix bug in Winforms ListBox + // that autoselects first item when no items are selected + // -1 = multi or set to this after 1st initialization + // if this = 0 and only 1 item selected, + // that means item was autoselected, so clear all items. public int singleselectedindex { get; set; } - private void lb_SelectedIndexChanged(object sender, EventArgs e) { ListBoxMulti tmp = (ListBoxMulti)sender; @@ -36,6 +43,7 @@ namespace Volian.Controls.Library } + //remove event when get rid of object private void ListBoxMulti_Disposed(object sender, EventArgs e) { SelectedIndexChanged -= lb_SelectedIndexChanged; diff --git a/PROMS/Volian.Controls.Library/frmEPAnnotationDetails.cs b/PROMS/Volian.Controls.Library/frmEPAnnotationDetails.cs index 44c3cada..6b66749e 100644 --- a/PROMS/Volian.Controls.Library/frmEPAnnotationDetails.cs +++ b/PROMS/Volian.Controls.Library/frmEPAnnotationDetails.cs @@ -168,6 +168,7 @@ namespace Volian.Controls.Library foreach (KeyValuePair pair in _DicMultiRO) { + //clear all items at start in case items were autoselected - bug in Winforms ListBox pair.Value.ClearSelected(); string val = MyConfig.GetValue("EP", pair.Key); if (val != null && val != "") @@ -180,6 +181,10 @@ namespace Volian.Controls.Library pair.Value.SetSelected(pair.Value.FindString(text), true); } } + + //set this to -1 after initial setting of values + //this will help to fix bug in Winforms ListBox + //that autoselects first item when no items are selected pair.Value.singleselectedindex = -1; }