1 | using System.Collections.Generic;
|
---|
2 | using System.Drawing;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Windows.Forms;
|
---|
5 |
|
---|
6 | namespace 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 | }
|
---|