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 |
|
---|
15 | public JsonItemValidValuesControl(JsonItemVM vm) : base(vm) {
|
---|
16 | InitializeComponent();
|
---|
17 | foreach (var i in VM.Item.Range) {
|
---|
18 | AddOption((string)i);
|
---|
19 | if(i == VM.Item.Value) {
|
---|
20 | comboBoxValues.SelectedItem = (string)i;
|
---|
21 | }
|
---|
22 | }
|
---|
23 |
|
---|
24 | }
|
---|
25 |
|
---|
26 | private void AddOption(string opt) {
|
---|
27 | AddComboOption(opt);
|
---|
28 | TextBox tb = new TextBox();
|
---|
29 | tb.Text = opt;
|
---|
30 | tb.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
---|
31 | tb.Size = new Size(420, 20);
|
---|
32 | tb.ReadOnly = true;
|
---|
33 |
|
---|
34 | CheckBox checkBox = new CheckBox();
|
---|
35 | checkBox.Checked = true;
|
---|
36 |
|
---|
37 | checkBox.CheckStateChanged += (o, args) => {
|
---|
38 | if (checkBox.Checked)
|
---|
39 | AddComboOption(opt);
|
---|
40 | else
|
---|
41 | RemoveComboOption(opt);
|
---|
42 | };
|
---|
43 | tableOptions.Controls.Add(checkBox);
|
---|
44 | tableOptions.Controls.Add(tb);
|
---|
45 | }
|
---|
46 |
|
---|
47 | private void AddComboOption(string opt) {
|
---|
48 | comboBoxValues.Items.Add(opt);
|
---|
49 | IList<string> items = new List<string>();
|
---|
50 | foreach (var i in comboBoxValues.Items) {
|
---|
51 | items.Add((string)i);
|
---|
52 | }
|
---|
53 | VM.Item.Range = items;
|
---|
54 | tableOptions.Refresh();
|
---|
55 | }
|
---|
56 |
|
---|
57 | private void RemoveComboOption(string opt) {
|
---|
58 | comboBoxValues.Items.Remove(opt);
|
---|
59 | IList<string> items = new List<string>();
|
---|
60 | foreach (var i in comboBoxValues.Items) {
|
---|
61 | items.Add((string)i);
|
---|
62 | }
|
---|
63 | VM.Item.Range = items;
|
---|
64 | tableOptions.Refresh();
|
---|
65 | }
|
---|
66 |
|
---|
67 | private void comboBoxValues_SelectedValueChanged(object sender, EventArgs e) {
|
---|
68 | VM.Item.Value = (string)comboBoxValues.SelectedItem;
|
---|
69 | }
|
---|
70 |
|
---|
71 | private void JsonItemValidValuesControl_Load(object sender, EventArgs e) {
|
---|
72 |
|
---|
73 | }
|
---|
74 | }
|
---|
75 | }
|
---|