Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views/JsonItemValidValuesControl.cs @ 17431

Last change on this file since 17431 was 17417, checked in by dpiringe, 4 years ago

#3026:

  • added initial VM (ArrayValueVM) and control for array values (JsonItemArrayValueControl)
  • new types of JsonItems for better type safety:
    • for arrays: DoubleArrayJsonItem, IntArrayJsonItem, BoolArrayJsonItem
    • for matrix: DoubleMatrixJsonItem, IntMatrixJsonItem, BoolMatrixJsonItem
  • refactored ValueTypeArrayConverter and ValueTypeMatrixConverter -> better type safety with new JsonItems
  • enhanced StringValueVM and implemented JsonItemValidValuesControl with MVVM architecture
  • the VM of JsonItemBaseControl is now protected (was private)
  • improved JsonItem<V,R> -> now handles JTokens correctly
File size: 2.0 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 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}
Note: See TracBrowser for help on using the repository browser.