1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.ComponentModel;
|
---|
4 | using System.Drawing;
|
---|
5 | using System.Data;
|
---|
6 | using System.Linq;
|
---|
7 | using System.Text;
|
---|
8 | using System.Threading.Tasks;
|
---|
9 | using System.Windows.Forms;
|
---|
10 |
|
---|
11 | namespace HeuristicLab.JsonInterface.OptimizerIntegration {
|
---|
12 | public partial class JsonItemValidValuesControl : JsonItemBaseControl {
|
---|
13 |
|
---|
14 | public JsonItemValidValuesControl(StringValueVM vm) : base(vm) {
|
---|
15 | InitializeComponent();
|
---|
16 | foreach (var i in VM.Item.Range)
|
---|
17 | SetupOption((string)i);
|
---|
18 |
|
---|
19 | comboBoxValues.DataBindings.Add("SelectedItem", VM, nameof(StringValueVM.Value));
|
---|
20 | }
|
---|
21 |
|
---|
22 | private void SetupOption(string opt) {
|
---|
23 | AddComboOption(opt);
|
---|
24 | TextBox tb = new TextBox();
|
---|
25 | tb.Text = opt;
|
---|
26 | tb.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
---|
27 | tb.Size = new Size(420, 20);
|
---|
28 | tb.ReadOnly = true;
|
---|
29 |
|
---|
30 | CheckBox checkBox = new CheckBox();
|
---|
31 | checkBox.Checked = true;
|
---|
32 |
|
---|
33 | checkBox.CheckStateChanged += (o, args) => {
|
---|
34 | if (checkBox.Checked)
|
---|
35 | AddComboOption(opt);
|
---|
36 | else
|
---|
37 | RemoveComboOption(opt);
|
---|
38 | };
|
---|
39 | tableOptions.Controls.Add(checkBox);
|
---|
40 | tableOptions.Controls.Add(tb);
|
---|
41 | }
|
---|
42 |
|
---|
43 | private void AddComboOption(string opt) {
|
---|
44 | comboBoxValues.Items.Add(opt);
|
---|
45 | IList<string> items = new List<string>();
|
---|
46 | foreach (var i in comboBoxValues.Items) {
|
---|
47 | items.Add((string)i);
|
---|
48 | }
|
---|
49 | ((StringValueVM)VM).Range = items;
|
---|
50 | comboBoxValues.Enabled = true;
|
---|
51 | tableOptions.Refresh();
|
---|
52 | }
|
---|
53 |
|
---|
54 | private void RemoveComboOption(string opt) {
|
---|
55 | comboBoxValues.Items.Remove(opt);
|
---|
56 | IList<string> items = new List<string>();
|
---|
57 | foreach (var i in comboBoxValues.Items) {
|
---|
58 | items.Add((string)i);
|
---|
59 | }
|
---|
60 | ((StringValueVM)VM).Range = items;
|
---|
61 | if (((StringValueVM)VM).Range.Count() <= 0) {
|
---|
62 | comboBoxValues.Enabled = false;
|
---|
63 | comboBoxValues.SelectedIndex = -1;
|
---|
64 | }
|
---|
65 | tableOptions.Refresh();
|
---|
66 | }
|
---|
67 | }
|
---|
68 | }
|
---|