Development #570

Merged
djankowski merged 40 commits from Development into master 2025-06-23 14:58:29 -04:00
2 changed files with 14 additions and 1 deletions
Showing only changes of commit 9fdbdb05f4 - Show all commits

View File

@ -7,6 +7,8 @@ using System.Windows.Forms;
namespace Volian.Controls.Library 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 partial class ListBoxMulti : ListBox
{ {
public ListBoxMulti() public ListBoxMulti()
@ -19,8 +21,13 @@ namespace Volian.Controls.Library
Disposed += ListBoxMulti_Disposed; 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; } public int singleselectedindex { get; set; }
private void lb_SelectedIndexChanged(object sender, EventArgs e) private void lb_SelectedIndexChanged(object sender, EventArgs e)
{ {
ListBoxMulti tmp = (ListBoxMulti)sender; 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) private void ListBoxMulti_Disposed(object sender, EventArgs e)
{ {
SelectedIndexChanged -= lb_SelectedIndexChanged; SelectedIndexChanged -= lb_SelectedIndexChanged;

View File

@ -168,6 +168,7 @@ namespace Volian.Controls.Library
foreach (KeyValuePair<string, ListBoxMulti> pair in _DicMultiRO) foreach (KeyValuePair<string, ListBoxMulti> pair in _DicMultiRO)
{ {
//clear all items at start in case items were autoselected - bug in Winforms ListBox
pair.Value.ClearSelected(); pair.Value.ClearSelected();
string val = MyConfig.GetValue("EP", pair.Key); string val = MyConfig.GetValue("EP", pair.Key);
if (val != null && val != "") if (val != null && val != "")
@ -180,6 +181,10 @@ namespace Volian.Controls.Library
pair.Value.SetSelected(pair.Value.FindString(text), true); 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; pair.Value.singleselectedindex = -1;
} }