Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views/JsonItemConcreteItemArrayControl.cs @ 17712

Last change on this file since 17712 was 17519, checked in by dpiringe, 5 years ago

#3026:

  • added error output for failed runner initialization
  • reorganised some final view models
  • TargetedJsonItemType (in JsonItemVMBase) now automatically returns the type of the defined JsonItem
  • code cleanup
  • refactored RegressionProblemDataConverter
  • added lots of comments
  • added new view for StringArrayJsonItem
  • added new UI component for concrete restricted items and used it in JsonItemConcreteItemArrayControl and JsonItemValidValuesControl
File size: 2.6 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Drawing;
5using System.Data;
6using System.Linq;
7using System.Text;
8using System.Threading.Tasks;
9using System.Windows.Forms;
10
11namespace 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}
Note: See TracBrowser for help on using the repository browser.