C2025-023 - Electronic Procedures - Modifications to PROMS (checkin #3 - fix winforms select first item bug in listboxes)

This commit is contained in:
Matthew Schill 2025-04-10 08:53:27 -04:00
parent 389b9e382b
commit d392131005
3 changed files with 61 additions and 10 deletions

View File

@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Volian.Controls.Library
{
public partial class ListBoxMulti : ListBox
{
public ListBoxMulti()
{
Visible = true;
SelectionMode = SelectionMode.MultiSimple;
SelectedIndexChanged += lb_SelectedIndexChanged;
Disposed += ListBoxMulti_Disposed;
}
public int singleselectedindex { get; set; }
private void lb_SelectedIndexChanged(object sender, EventArgs e)
{
ListBoxMulti tmp = (ListBoxMulti)sender;
if (tmp.SelectedItems.Count == 1 && tmp.singleselectedindex == 0)
{
tmp.ClearSelected();
}
else if (tmp.SelectedItems.Count == 1)
tmp.singleselectedindex = tmp.SelectedIndex;
else
tmp.singleselectedindex = -1;
}
private void ListBoxMulti_Disposed(object sender, EventArgs e)
{
SelectedIndexChanged -= lb_SelectedIndexChanged;
}
}
}

View File

@ -280,6 +280,9 @@
<DependentUpon>ImageItem.cs</DependentUpon>
</Compile>
<Compile Include="LinkText.cs" />
<Compile Include="ListBoxMulti.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="PreviewMultiLineRO.cs">
<SubType>Form</SubType>
</Compile>

View File

@ -24,7 +24,7 @@ namespace Volian.Controls.Library
private Dictionary<string, CheckBox> _DicCheckBox;
private Dictionary<string, ComboBox> _DicComboBox;
private Dictionary<string, ComboBox> _DicSingleRO;
private Dictionary<string, ListBox> _DicMultiRO;
private Dictionary<string, ListBoxMulti> _DicMultiRO;
private string multiseparator = ",";
@ -35,7 +35,7 @@ namespace Volian.Controls.Library
_DicCheckBox = new Dictionary<string, CheckBox>();
_DicComboBox = new Dictionary<string, ComboBox>();
_DicSingleRO = new Dictionary<string, ComboBox>();
_DicMultiRO = new Dictionary<string, ListBox>();
_DicMultiRO = new Dictionary<string, ListBoxMulti>();
InitializeSpecificControls(currAnn);
_MyStepTabRibbon = new StepTabRibbon();
}
@ -138,16 +138,12 @@ namespace Volian.Controls.Library
}
if (EP.type.ToLower() == "romulti")
{
ListBox lb = new ListBox();
lb.Visible = true;
ListBoxMulti lb = new ListBoxMulti();
List<ROListItem> tmps = EP.getROList(currAnn, false);
lb.DisplayMember = "Text";
lb.ValueMember = "Value";
lb.Width = TextRenderer.MeasureText(tmps.OrderByDescending(x => x.Text.Length).First().Text, lb.Font).Width + SystemInformation.VerticalScrollBarWidth;
lb.SelectionMode = SelectionMode.MultiSimple;
//lb.IsSynchronizedWithCurrentItem = false;
lb.DataSource = tmps;
_DicMultiRO.Add(EP.name, lb);
@ -170,7 +166,7 @@ namespace Volian.Controls.Library
pair.Value.SelectedValue = -1;
}
foreach (KeyValuePair<string, ListBox> pair in _DicMultiRO)
foreach (KeyValuePair<string, ListBoxMulti> pair in _DicMultiRO)
{
pair.Value.ClearSelected();
string val = MyConfig.GetValue("EP", pair.Key);
@ -184,7 +180,10 @@ namespace Volian.Controls.Library
pair.Value.SetSelected(pair.Value.FindString(text), true);
}
}
pair.Value.singleselectedindex = -1;
}
}
private void FieldStepRTB_Enter(object sender, EventArgs e)
@ -246,7 +245,7 @@ namespace Volian.Controls.Library
}
else if (EP.type.ToLower() == "romulti")
{
ListBox lbcur = _DicMultiRO[EP.name];
ListBoxMulti lbcur = _DicMultiRO[EP.name];
string newvalues = String.Join(multiseparator, lbcur.SelectedItems.OfType<ROListItem>().Select(item => item.Value));
string oldvalues = MyConfig.GetValue("EP", EP.name);
if (newvalues != oldvalues)
@ -287,6 +286,11 @@ namespace Volian.Controls.Library
tb.Enter -= FieldStepRTB_Enter;
}
foreach (ListBoxMulti lb in _DicMultiRO.Values)
{
lb.Dispose();
}
Load -= Form1Load_setDefaults;
}
}