Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views/JsonItemValidValuesControl.cs @ 17560

Last change on this file since 17560 was 17560, checked in by dpiringe, 4 years ago

#3026:

  • added an extra loop to add empty default results in Runner (to prevent not existing results)
  • fixed a bug in JsonItemValidValuesControl, now the dropdown should not reset the default value
File size: 2.0 KB
Line 
1using System.Collections.Generic;
2using System.Drawing;
3using System.Linq;
4using System.Windows.Forms;
5
6namespace HeuristicLab.JsonInterface.OptimizerIntegration {
7  public partial class JsonItemValidValuesControl : UserControl {
8
9    StringValueVM VM { get; set; }
10
11    public JsonItemValidValuesControl(StringValueVM vm) {
12      InitializeComponent();
13      VM = vm;
14      if (VM.Item.ConcreteRestrictedItems != null) {
15        string tmp = VM.Value;
16        concreteItemsRestrictor.OnChecked += AddComboOption;
17        concreteItemsRestrictor.OnUnchecked += RemoveComboOption;
18        concreteItemsRestrictor.Init(VM.Item.ConcreteRestrictedItems);
19        VM.Value = tmp;
20        comboBoxValues.DataBindings.Add("SelectedItem", VM, nameof(StringValueVM.Value));
21      } else {
22        groupBoxRange.Hide();
23        TextBox tb = new TextBox();
24        tableLayoutPanel2.Controls.Remove(comboBoxValues);
25        tableLayoutPanel2.Controls.Add(tb, 1, 0);
26
27        tb.Location = comboBoxValues.Location;
28        tb.Margin = new Padding(0);
29        tb.Size = new Size(comboBoxValues.Size.Width, 20);
30        tb.Anchor = AnchorStyles.Top | AnchorStyles.Left;
31        tb.Dock = DockStyle.Fill;
32
33        tb.DataBindings.Add("Text", VM, nameof(StringValueVM.Value));
34        tb.Show();
35      }
36    }
37
38    private void AddComboOption(object opt) {
39      comboBoxValues.Items.Add(opt);
40      IList<string> items = new List<string>();
41      foreach (var i in comboBoxValues.Items) {
42        items.Add((string)i);
43      }
44      VM.Range = items;
45      comboBoxValues.Enabled = true;
46    }
47
48    private void RemoveComboOption(object opt) {
49      comboBoxValues.Items.Remove(opt);
50      IList<string> items = new List<string>();
51      foreach (var i in comboBoxValues.Items) {
52        items.Add((string)i);
53      }
54      VM.Range = items;
55
56      if (VM.Range.Count() <= 0) {
57        comboBoxValues.Enabled = false;
58        comboBoxValues.SelectedIndex = -1;
59      }
60    }
61  }
62}
Note: See TracBrowser for help on using the repository browser.