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 JsonItemConcreteItemArrayControl : UserControl {
|
---|
13 | private StringArrayVM VM { get; set; }
|
---|
14 | private DataGridViewComboBoxColumn ComboBox { get; set; }
|
---|
15 | public JsonItemConcreteItemArrayControl(StringArrayVM vm) {
|
---|
16 | InitializeComponent();
|
---|
17 | dataGridView.AllowUserToDeleteRows = true;
|
---|
18 | VM = vm;
|
---|
19 | if (VM.Item.ConcreteRestrictedItems != null) {
|
---|
20 | ComboBox = new DataGridViewComboBoxColumn();
|
---|
21 | dataGridView.Columns.Add(ComboBox);
|
---|
22 | concreteItemsRestrictor.OnChecked += AddComboOption;
|
---|
23 | concreteItemsRestrictor.OnUnchecked += RemoveComboOption;
|
---|
24 | concreteItemsRestrictor.Init(VM.Item.ConcreteRestrictedItems);
|
---|
25 | } else {
|
---|
26 | dataGridView.AllowUserToAddRows = true;
|
---|
27 | dataGridView.Columns.Add(new DataGridViewTextBoxColumn());
|
---|
28 | groupBox2.Visible = false;
|
---|
29 | tableLayoutPanel1.RowStyles[0].SizeType = SizeType.Percent;
|
---|
30 | tableLayoutPanel1.RowStyles[0].Height = 100.0f;
|
---|
31 | }
|
---|
32 | if(VM.Value != null) {
|
---|
33 | foreach (var val in VM.Value) {
|
---|
34 | dataGridView.Rows.Add(val);
|
---|
35 | }
|
---|
36 | }
|
---|
37 | }
|
---|
38 |
|
---|
39 | private void AddComboOption(object opt) {
|
---|
40 | ComboBox.Items.Add(opt);
|
---|
41 | IList<string> items = new List<string>();
|
---|
42 | foreach (var i in ComboBox.Items) {
|
---|
43 | items.Add((string)i);
|
---|
44 | }
|
---|
45 | VM.Range = items;
|
---|
46 | dataGridView.AllowUserToAddRows = true;
|
---|
47 | }
|
---|
48 |
|
---|
49 | private void RemoveComboOption(object opt) {
|
---|
50 | ComboBox.Items.Remove(opt);
|
---|
51 | IList<string> items = new List<string>();
|
---|
52 | foreach (var i in ComboBox.Items) {
|
---|
53 | items.Add((string)i);
|
---|
54 | }
|
---|
55 | VM.Range = items;
|
---|
56 |
|
---|
57 | if (VM.Range.Count() <= 0) {
|
---|
58 | dataGridView.Rows.Clear();
|
---|
59 | dataGridView.AllowUserToAddRows = false;
|
---|
60 | }
|
---|
61 | }
|
---|
62 |
|
---|
63 | private void BuildValue() {
|
---|
64 | IList<string> list = new List<string>();
|
---|
65 | for (int r = 0; r < dataGridView.Rows.Count; ++r) {
|
---|
66 | var value = dataGridView[0, r].Value;
|
---|
67 | if(value != null)
|
---|
68 | list.Add((string)value);
|
---|
69 | }
|
---|
70 | VM.Value = list.ToArray();
|
---|
71 | }
|
---|
72 |
|
---|
73 | private void dataGridView_RowsRemoved(object sender, DataGridViewRowsRemovedEventArgs e) {
|
---|
74 | BuildValue();
|
---|
75 | }
|
---|
76 |
|
---|
77 | private void dataGridView_CellEndEdit(object sender, DataGridViewCellEventArgs e) {
|
---|
78 | BuildValue();
|
---|
79 | }
|
---|
80 | }
|
---|
81 | } |
---|