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 | private void AddOption(string opt) {
|
---|
26 | comboBoxValues.Items.Add(opt);
|
---|
27 | TextBox tb = new TextBox();
|
---|
28 | tb.Text = opt;
|
---|
29 | tb.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
---|
30 | tb.Size = new Size(420, 20);
|
---|
31 | tb.ReadOnly = true;
|
---|
32 | Button btn = new Button();
|
---|
33 | btn.Text = "-";
|
---|
34 | btn.Size = new Size(20, 20);
|
---|
35 | btn.Click += (o, args) => {
|
---|
36 | tableOptions.Controls.Remove(tb);
|
---|
37 | tableOptions.Controls.Remove(btn);
|
---|
38 | comboBoxValues.Items.Remove(tb.Text);
|
---|
39 | IList<string> items = new List<string>();
|
---|
40 | foreach(var i in comboBoxValues.Items) {
|
---|
41 | items.Add((string)i);
|
---|
42 | }
|
---|
43 | VM.Item.Range = items;
|
---|
44 | tableOptions.Refresh();
|
---|
45 | };
|
---|
46 | tableOptions.Controls.Add(tb);
|
---|
47 | tableOptions.Controls.Add(btn);
|
---|
48 | }
|
---|
49 |
|
---|
50 | private void buttonAdd_Click(object sender, EventArgs e) {
|
---|
51 | string newOption = textBoxAdd.Text;
|
---|
52 | if (string.IsNullOrWhiteSpace(newOption)) return;
|
---|
53 | textBoxAdd.Text = "";
|
---|
54 | AddOption(newOption);
|
---|
55 | }
|
---|
56 |
|
---|
57 | private void comboBoxValues_SelectedValueChanged(object sender, EventArgs e) {
|
---|
58 | VM.Item.Value = (string)comboBoxValues.SelectedItem;
|
---|
59 | }
|
---|
60 |
|
---|
61 | private void JsonItemValidValuesControl_Load(object sender, EventArgs e) {
|
---|
62 |
|
---|
63 | }
|
---|
64 | }
|
---|
65 | }
|
---|