Free cookie consent management tool by TermsFeed Policy Generator

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

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

#3026:

  • added error output for failed runner initialization
  • reorganised some final view models
  • TargetedJsonItemType (in JsonItemVMBase) now automatically returns the type of the defined JsonItem
  • code cleanup
  • refactored RegressionProblemDataConverter
  • added lots of comments
  • added new view for StringArrayJsonItem
  • added new UI component for concrete restricted items and used it in JsonItemConcreteItemArrayControl and JsonItemValidValuesControl
File size: 1.9 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        concreteItemsRestrictor.OnChecked += AddComboOption;
16        concreteItemsRestrictor.OnUnchecked += RemoveComboOption;
17        concreteItemsRestrictor.Init(VM.Item.ConcreteRestrictedItems);
18        comboBoxValues.DataBindings.Add("SelectedItem", VM, nameof(StringValueVM.Value));
19      } else {
20        groupBoxRange.Hide();
21        TextBox tb = new TextBox();
22        tableLayoutPanel2.Controls.Remove(comboBoxValues);
23        tableLayoutPanel2.Controls.Add(tb, 1, 0);
24
25        tb.Location = comboBoxValues.Location;
26        tb.Margin = new Padding(0);
27        tb.Size = new Size(comboBoxValues.Size.Width, 20);
28        tb.Anchor = AnchorStyles.Top | AnchorStyles.Left;
29        tb.Dock = DockStyle.Fill;
30
31        tb.DataBindings.Add("Text", VM, nameof(StringValueVM.Value));
32        tb.Show();
33      }
34    }
35
36    private void AddComboOption(object opt) {
37      comboBoxValues.Items.Add(opt);
38      IList<string> items = new List<string>();
39      foreach (var i in comboBoxValues.Items) {
40        items.Add((string)i);
41      }
42      VM.Range = items;
43      comboBoxValues.Enabled = true;
44    }
45
46    private void RemoveComboOption(object opt) {
47      comboBoxValues.Items.Remove(opt);
48      IList<string> items = new List<string>();
49      foreach (var i in comboBoxValues.Items) {
50        items.Add((string)i);
51      }
52      VM.Range = items;
53      if (VM.Range.Count() <= 0) {
54        comboBoxValues.Enabled = false;
55        comboBoxValues.SelectedIndex = -1;
56      }
57    }
58  }
59}
Note: See TracBrowser for help on using the repository browser.