Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/25/20 17:18:00 (5 years ago)
Author:
dpiringe
Message:

#3026:

  • renamed ResultItem to ResultJsonItem
  • implemented RegressionProblemDataConverter
  • added support for "named matrices" (named = rows and columns have names) -> INamedMatrixJsonItem incl. base classes and views
  • added a bool property Active in IJsonItem -> marks items, which should be written into the template
Location:
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views/ExportJsonDialog.Designer.cs

    r17446 r17451  
    3030      this.groupBoxDetails = new System.Windows.Forms.GroupBox();
    3131      this.panelParameterDetails = new System.Windows.Forms.Panel();
    32       this.resultItems = new System.Windows.Forms.CheckedListBox();
    33       this.groupBox3 = new System.Windows.Forms.GroupBox();
     32      this.splitContainer1 = new System.Windows.Forms.SplitContainer();
    3433      this.treeViewResults = new System.Windows.Forms.TreeView();
     34      this.groupBox = new System.Windows.Forms.GroupBox();
     35      this.panelResultDetails = new System.Windows.Forms.Panel();
    3536      this.splitContainer2 = new System.Windows.Forms.SplitContainer();
    3637      this.tabControl1 = new System.Windows.Forms.TabControl();
     
    4041      this.textBoxTemplateName = new System.Windows.Forms.TextBox();
    4142      this.errorProvider = new System.Windows.Forms.ErrorProvider(this.components);
    42       this.splitContainer1 = new System.Windows.Forms.SplitContainer();
    43       this.groupBox = new System.Windows.Forms.GroupBox();
    44       this.panelResultDetails = new System.Windows.Forms.Panel();
    4543      this.jsonItemBindingSource = new System.Windows.Forms.BindingSource(this.components);
    4644      this.groupBoxDetails.SuspendLayout();
    47       this.groupBox3.SuspendLayout();
     45      ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
     46      this.splitContainer1.Panel1.SuspendLayout();
     47      this.splitContainer1.Panel2.SuspendLayout();
     48      this.splitContainer1.SuspendLayout();
     49      this.groupBox.SuspendLayout();
    4850      ((System.ComponentModel.ISupportInitialize)(this.splitContainer2)).BeginInit();
    4951      this.splitContainer2.Panel1.SuspendLayout();
     
    5456      this.tabPage2.SuspendLayout();
    5557      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit();
    56       ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
    57       this.splitContainer1.Panel1.SuspendLayout();
    58       this.splitContainer1.Panel2.SuspendLayout();
    59       this.splitContainer1.SuspendLayout();
    60       this.groupBox.SuspendLayout();
    6158      ((System.ComponentModel.ISupportInitialize)(this.jsonItemBindingSource)).BeginInit();
    6259      this.SuspendLayout();
     
    8582      this.treeView.Location = new System.Drawing.Point(0, 6);
    8683      this.treeView.Name = "treeView";
    87       this.treeView.Size = new System.Drawing.Size(370, 493);
     84      this.treeView.Size = new System.Drawing.Size(380, 492);
    8885      this.treeView.TabIndex = 3;
    8986      this.treeView.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeView_AfterSelect);
     
    9592      this.groupBoxDetails.Location = new System.Drawing.Point(0, 0);
    9693      this.groupBoxDetails.Name = "groupBoxDetails";
    97       this.groupBoxDetails.Size = new System.Drawing.Size(422, 499);
     94      this.groupBoxDetails.Size = new System.Drawing.Size(412, 499);
    9895      this.groupBoxDetails.TabIndex = 4;
    9996      this.groupBoxDetails.TabStop = false;
     
    106103      this.panelParameterDetails.Location = new System.Drawing.Point(3, 16);
    107104      this.panelParameterDetails.Name = "panelParameterDetails";
    108       this.panelParameterDetails.Size = new System.Drawing.Size(416, 480);
     105      this.panelParameterDetails.Size = new System.Drawing.Size(406, 480);
    109106      this.panelParameterDetails.TabIndex = 0;
    110107      //
    111       // resultItems
    112       //
    113       this.resultItems.Dock = System.Windows.Forms.DockStyle.Fill;
    114       this.resultItems.FormattingEnabled = true;
    115       this.resultItems.Location = new System.Drawing.Point(0, 6);
    116       this.resultItems.Name = "resultItems";
    117       this.resultItems.Size = new System.Drawing.Size(373, 393);
    118       this.resultItems.TabIndex = 5;
    119       this.resultItems.SelectedValueChanged += new System.EventHandler(this.resultItems_SelectedValueChanged);
    120       //
    121       // groupBox3
    122       //
    123       this.groupBox3.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    124             | System.Windows.Forms.AnchorStyles.Left)
    125             | System.Windows.Forms.AnchorStyles.Right)));
    126       this.groupBox3.Controls.Add(this.splitContainer1);
    127       this.groupBox3.Controls.Add(this.treeViewResults);
    128       this.groupBox3.Location = new System.Drawing.Point(6, 6);
    129       this.groupBox3.Name = "groupBox3";
    130       this.groupBox3.Size = new System.Drawing.Size(790, 493);
    131       this.groupBox3.TabIndex = 7;
    132       this.groupBox3.TabStop = false;
    133       this.groupBox3.Text = "Result Elements";
     108      // splitContainer1
     109      //
     110      this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
     111      this.splitContainer1.Location = new System.Drawing.Point(3, 3);
     112      this.splitContainer1.Name = "splitContainer1";
     113      //
     114      // splitContainer1.Panel1
     115      //
     116      this.splitContainer1.Panel1.Controls.Add(this.treeViewResults);
     117      this.splitContainer1.Panel1.Padding = new System.Windows.Forms.Padding(0, 6, 0, 1);
     118      //
     119      // splitContainer1.Panel2
     120      //
     121      this.splitContainer1.Panel2.Controls.Add(this.groupBox);
     122      this.splitContainer1.Size = new System.Drawing.Size(796, 499);
     123      this.splitContainer1.SplitterDistance = 380;
     124      this.splitContainer1.TabIndex = 7;
    134125      //
    135126      // treeViewResults
    136127      //
    137128      this.treeViewResults.CheckBoxes = true;
    138       this.treeViewResults.Location = new System.Drawing.Point(6, 19);
     129      this.treeViewResults.Dock = System.Windows.Forms.DockStyle.Fill;
     130      this.treeViewResults.Location = new System.Drawing.Point(0, 6);
    139131      this.treeViewResults.Name = "treeViewResults";
    140       this.treeViewResults.Size = new System.Drawing.Size(777, 63);
     132      this.treeViewResults.Size = new System.Drawing.Size(380, 492);
    141133      this.treeViewResults.TabIndex = 6;
     134      this.treeViewResults.AfterCheck += new System.Windows.Forms.TreeViewEventHandler(this.treeViewResults_AfterCheck);
     135      this.treeViewResults.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeViewResults_AfterSelect);
     136      //
     137      // groupBox
     138      //
     139      this.groupBox.Controls.Add(this.panelResultDetails);
     140      this.groupBox.Dock = System.Windows.Forms.DockStyle.Fill;
     141      this.groupBox.Location = new System.Drawing.Point(0, 0);
     142      this.groupBox.Name = "groupBox";
     143      this.groupBox.Size = new System.Drawing.Size(412, 499);
     144      this.groupBox.TabIndex = 5;
     145      this.groupBox.TabStop = false;
     146      this.groupBox.Text = "Details";
     147      //
     148      // panelResultDetails
     149      //
     150      this.panelResultDetails.AutoScroll = true;
     151      this.panelResultDetails.Dock = System.Windows.Forms.DockStyle.Fill;
     152      this.panelResultDetails.Location = new System.Drawing.Point(3, 16);
     153      this.panelResultDetails.Name = "panelResultDetails";
     154      this.panelResultDetails.Size = new System.Drawing.Size(406, 480);
     155      this.panelResultDetails.TabIndex = 0;
    142156      //
    143157      // splitContainer2
     
    150164      //
    151165      this.splitContainer2.Panel1.Controls.Add(this.treeView);
    152       this.splitContainer2.Panel1.Padding = new System.Windows.Forms.Padding(0, 6, 0, 0);
     166      this.splitContainer2.Panel1.Padding = new System.Windows.Forms.Padding(0, 6, 0, 1);
    153167      //
    154168      // splitContainer2.Panel2
     
    156170      this.splitContainer2.Panel2.Controls.Add(this.groupBoxDetails);
    157171      this.splitContainer2.Size = new System.Drawing.Size(796, 499);
    158       this.splitContainer2.SplitterDistance = 370;
     172      this.splitContainer2.SplitterDistance = 380;
    159173      this.splitContainer2.TabIndex = 9;
    160174      //
     
    185199      // tabPage2
    186200      //
    187       this.tabPage2.Controls.Add(this.groupBox3);
     201      this.tabPage2.Controls.Add(this.splitContainer1);
    188202      this.tabPage2.Location = new System.Drawing.Point(4, 22);
    189203      this.tabPage2.Name = "tabPage2";
     
    219233      this.errorProvider.BlinkStyle = System.Windows.Forms.ErrorBlinkStyle.NeverBlink;
    220234      this.errorProvider.ContainerControl = this;
    221       //
    222       // splitContainer1
    223       //
    224       this.splitContainer1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    225             | System.Windows.Forms.AnchorStyles.Left)
    226             | System.Windows.Forms.AnchorStyles.Right)));
    227       this.splitContainer1.Location = new System.Drawing.Point(6, 88);
    228       this.splitContainer1.Name = "splitContainer1";
    229       //
    230       // splitContainer1.Panel1
    231       //
    232       this.splitContainer1.Panel1.Controls.Add(this.resultItems);
    233       this.splitContainer1.Panel1.Padding = new System.Windows.Forms.Padding(0, 6, 0, 0);
    234       //
    235       // splitContainer1.Panel2
    236       //
    237       this.splitContainer1.Panel2.Controls.Add(this.groupBox);
    238       this.splitContainer1.Size = new System.Drawing.Size(778, 399);
    239       this.splitContainer1.SplitterDistance = 373;
    240       this.splitContainer1.TabIndex = 7;
    241       //
    242       // groupBox
    243       //
    244       this.groupBox.Controls.Add(this.panelResultDetails);
    245       this.groupBox.Dock = System.Windows.Forms.DockStyle.Fill;
    246       this.groupBox.Location = new System.Drawing.Point(0, 0);
    247       this.groupBox.Name = "groupBox";
    248       this.groupBox.Size = new System.Drawing.Size(401, 399);
    249       this.groupBox.TabIndex = 5;
    250       this.groupBox.TabStop = false;
    251       this.groupBox.Text = "Details";
    252       //
    253       // panelResultDetails
    254       //
    255       this.panelResultDetails.AutoScroll = true;
    256       this.panelResultDetails.Dock = System.Windows.Forms.DockStyle.Fill;
    257       this.panelResultDetails.Location = new System.Drawing.Point(3, 16);
    258       this.panelResultDetails.Name = "panelResultDetails";
    259       this.panelResultDetails.Size = new System.Drawing.Size(395, 380);
    260       this.panelResultDetails.TabIndex = 0;
    261235      //
    262236      // jsonItemBindingSource
     
    278252      this.Text = "Export Json";
    279253      this.groupBoxDetails.ResumeLayout(false);
    280       this.groupBox3.ResumeLayout(false);
     254      this.splitContainer1.Panel1.ResumeLayout(false);
     255      this.splitContainer1.Panel2.ResumeLayout(false);
     256      ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit();
     257      this.splitContainer1.ResumeLayout(false);
     258      this.groupBox.ResumeLayout(false);
    281259      this.splitContainer2.Panel1.ResumeLayout(false);
    282260      this.splitContainer2.Panel2.ResumeLayout(false);
     
    287265      this.tabPage2.ResumeLayout(false);
    288266      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).EndInit();
    289       this.splitContainer1.Panel1.ResumeLayout(false);
    290       this.splitContainer1.Panel2.ResumeLayout(false);
    291       ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit();
    292       this.splitContainer1.ResumeLayout(false);
    293       this.groupBox.ResumeLayout(false);
    294267      ((System.ComponentModel.ISupportInitialize)(this.jsonItemBindingSource)).EndInit();
    295268      this.ResumeLayout(false);
     
    307280    private System.Windows.Forms.GroupBox groupBoxDetails;
    308281    private System.Windows.Forms.Panel panelParameterDetails;
    309     private System.Windows.Forms.CheckedListBox resultItems;
    310     private System.Windows.Forms.GroupBox groupBox3;
    311282    private System.Windows.Forms.SplitContainer splitContainer2;
    312283    private System.Windows.Forms.TabControl tabControl1;
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views/ExportJsonDialog.cs

    r17446 r17451  
    1717  public partial class ExportJsonDialog : Form {
    1818    private static FolderBrowserDialog FolderBrowserDialog { get; set; }
    19     private IDictionary<int, UserControl> Hash2Control { get; set; } = new Dictionary<int, UserControl>();
     19    private IDictionary<TreeNode, UserControl> Node2Control { get; set; } = new Dictionary<TreeNode, UserControl>();
    2020    private IDictionary<TreeNode, IJsonItemVM> Node2VM { get; set; } = new Dictionary<TreeNode, IJsonItemVM>();
     21    private IDictionary<Type, Type> JI2VM { get; set; }
    2122    private IJsonItem Root { get; set; }
    2223    private IOptimizer Optimizer { get; set; }
    2324    private IList<IJsonItemVM> VMs { get; set; }
    2425    private JCGenerator Generator { get; set; } = new JCGenerator();
    25     private IDictionary<string, IJsonItem> ResultItems { get; set; } = new Dictionary<string, IJsonItem>();
    2626
    2727    private IContent content;
     
    3333        VMs = new List<IJsonItemVM>();
    3434        treeView.Nodes.Clear();
    35         ResultItems.Clear();
    36         resultItems.Items.Clear();
     35        treeViewResults.Nodes.Clear();
    3736
    3837        Optimizer = content as IOptimizer;
     
    4746    }
    4847
    49     private void TreeView_AfterCheck(object sender, TreeViewEventArgs e) {
    50       if (e.Action != TreeViewAction.Unknown) {
    51         if (Node2VM.TryGetValue(e.Node, out IJsonItemVM vm)) {
    52           vm.Selected = e.Node.Checked;
    53         }
    54       }
    55     }
     48   
    5649
    57     private IDictionary<Type, Type> JI2VM { get; set; }
    5850
    5951    private void InitCache() {
     
    7163
    7264    private void exportButton_Click(object sender, EventArgs e) {
     65      // to set default value for disabled items
     66      JsonItemConverter.Inject(Optimizer, Root);
     67      /*
    7368      foreach (var x in VMs) {
    74         if (!(x is ResultItemVM) && !x.Selected) {
    75           x.Item.Parent.Children.Remove(x.Item);
     69        if (!x.Selected) {
     70          x.Item.Parent?.Children?.Remove(x.Item);
     71        } else if(x is ResultItemVM) {
     72          x.Item.Parent?.Children?.Remove(x.Item);
     73          Root.AddChildren(x.Item);
    7674        }
    7775      }
    78 
    79       foreach (var x in ResultItems.Values) {
    80         x.Parent.Children.Remove(x);
    81       }
    82 
    83       foreach (var x in resultItems.CheckedItems) {
    84         if (ResultItems.TryGetValue((string)x, out IJsonItem item)) {
    85           Root.AddChildren(item);
    86         }
    87       }
    88 
     76      */
     77     
    8978      IList<IJsonItem> faultyItems = new List<IJsonItem>();
    9079     
     
    11099
    111100    private void BuildTreeNode(TreeNode node, IJsonItem item) {
    112       RegisterItem(node, item);
     101      RegisterItem(node, item, treeView);
    113102      if (item.Children != null) {
    114103        foreach (var c in item.Children) {
    115104          if (IsDrawableItem(c)) {
    116             if (c is ResultItem) {
    117               resultItems.Items.Add(c.Name, true);
    118               ResultItems.Add(c.Name, c);
     105            if (c is ResultJsonItem) {
    119106              TreeNode childNode = new TreeNode(c.Name);
    120107              treeViewResults.Nodes.Add(childNode);
    121               RegisterItem(childNode, c);
    122               //Hash2Control.Add(c.GetHashCode(), new JsonItemBaseControl(new JsonItemVMBase() { Item = c }));
     108              RegisterItem(childNode, c, treeViewResults);
     109              if(Node2VM.TryGetValue(childNode, out IJsonItemVM vm))
     110                vm.Selected = true;
    123111            } else {
    124112              TreeNode childNode = new TreeNode(c.Name);
     
    131119    }
    132120
    133     private void RegisterItem(TreeNode node, IJsonItem item) {
     121    private void RegisterItem(TreeNode node, IJsonItem item, TreeView tv) {
    134122      if (JI2VM.TryGetValue(item.GetType(), out Type vmType)) {
    135123        IJsonItemVM vm = (IJsonItemVM)Activator.CreateInstance(vmType);
     
    137125        vm.Item = item;
    138126        vm.TreeNode = node;
    139         vm.TreeView = treeView;
    140         node.Checked = vm.Selected;
     127        vm.TreeView = tv;
     128        vm.Selected = false;
    141129
    142130        VMs.Add(vm);
    143131        Node2VM.Add(node, vm);
    144132        UserControl control = vm.Control;
    145         Hash2Control.Add(node.GetHashCode(), control);
     133        Node2Control.Add(node, control);
    146134      }
    147135    }
     
    155143      }
    156144     
    157       return b || (item.Value != null || item.Range != null || item.ActualName != null);
     145      return b || (item.Value != null || item.Range != null || item.ActualName != null || item is ResultJsonItem);
    158146    }
    159147   
    160148    private void treeView_AfterSelect(object sender, TreeViewEventArgs e) {
    161       if(Hash2Control.TryGetValue(treeView.SelectedNode.GetHashCode(), out UserControl control)) {
     149      if(Node2Control.TryGetValue(treeView.SelectedNode, out UserControl control)) {
    162150        SetControlOnPanel(control, panelParameterDetails);
     151      }
     152    }
     153
     154    private void treeViewResults_AfterSelect(object sender, TreeViewEventArgs e) {
     155      if (Node2Control.TryGetValue(treeViewResults.SelectedNode, out UserControl control)) {
     156        SetControlOnPanel(control, panelResultDetails);
    163157      }
    164158    }
     
    170164      } else {
    171165        errorProvider.SetError(textBoxTemplateName, null);
    172       }
    173     }
    174 
    175     private void resultItems_SelectedValueChanged(object sender, EventArgs e) {
    176       if(ResultItems.TryGetValue(resultItems.SelectedItem.ToString(), out IJsonItem item) &&
    177         Hash2Control.TryGetValue(item.GetHashCode(), out UserControl control)) {
    178         SetControlOnPanel(control, panelResultDetails);
    179166      }
    180167    }
     
    191178      panel.Refresh();
    192179    }
     180
     181    private void TreeView_AfterCheck(object sender, TreeViewEventArgs e) {
     182      if (e.Action != TreeViewAction.Unknown) {
     183        if (Node2VM.TryGetValue(e.Node, out IJsonItemVM vm)) {
     184          vm.Selected = e.Node.Checked;
     185        }
     186      }
     187    }
     188
     189    private void treeViewResults_AfterCheck(object sender, TreeViewEventArgs e) {
     190      if (e.Action != TreeViewAction.Unknown) {
     191        if (Node2VM.TryGetValue(e.Node, out IJsonItemVM vm)) {
     192          vm.Selected = e.Node.Checked;
     193        }
     194      }
     195    }
    193196  }
    194197}
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views/JsonItemMultiValueControl.cs

    r17446 r17451  
    1010
    1111namespace HeuristicLab.JsonInterface.OptimizerIntegration {
    12  
     12
     13  public class JsonItemDoubleNamedMatrixValueControl : JsonItemMultiValueControl<double> {
     14    protected override IEnumerable<string> RowNames {
     15      get => ((DoubleNamedMatrixValueVM)VM).RowNames;
     16      set => ((DoubleNamedMatrixValueVM)VM).RowNames = value;
     17    }
     18    protected override IEnumerable<string> ColumnNames {
     19      get => ((DoubleNamedMatrixValueVM)VM).ColumnNames;
     20      set => ((DoubleNamedMatrixValueVM)VM).ColumnNames = value;
     21    }
     22
     23    public JsonItemDoubleNamedMatrixValueControl(DoubleNamedMatrixValueVM vm) : base(vm, vm.Value) { }
     24
     25    protected override void SaveCellData(double data, int row, int col) {
     26      DoubleNamedMatrixValueVM vm = VM as DoubleNamedMatrixValueVM;
     27      vm.SetCellValue(data, row, col);
     28    }
     29  }
     30
    1331  public class JsonItemDoubleMatrixValueControl : JsonItemMultiValueControl<double> {
     32    protected override IEnumerable<string> RowNames { get => null; set { } }
     33    protected override IEnumerable<string> ColumnNames { get => null; set { } }
    1434
    1535    public JsonItemDoubleMatrixValueControl(DoubleMatrixValueVM vm) : base(vm, vm.Value) { }
     36
    1637    protected override void SaveCellData(double data, int row, int col) {
    1738      DoubleMatrixValueVM vm = VM as DoubleMatrixValueVM;
     
    2142
    2243  public class JsonItemIntArrayValueControl : JsonItemMultiValueControl<int> {
     44    protected override IEnumerable<string> RowNames { get => null; set { } }
     45    protected override IEnumerable<string> ColumnNames { get => null; set { } }
     46
    2347    public JsonItemIntArrayValueControl(IntArrayValueVM vm) : base(vm, vm.Value) { }
    2448
     
    3054
    3155  public class JsonItemDoubleArrayValueControl : JsonItemMultiValueControl<double> {
     56    protected override IEnumerable<string> RowNames { get => null; set { } }
     57    protected override IEnumerable<string> ColumnNames { get => null; set { } }
     58
    3259    public JsonItemDoubleArrayValueControl(DoubleArrayValueVM vm) : base(vm, vm.Value) { }
    3360
     
    6087    private T[][] Matrix { get; set; }
    6188
     89    protected abstract IEnumerable<string> RowNames { get; set; }
     90    protected abstract IEnumerable<string> ColumnNames { get; set; }
     91
    6292    public JsonItemMultiValueControl(IMatrixJsonItemVM vm, T[][] matrix) : base(vm) {
    6393      InitializeComponent();
     
    6696      checkBoxColumns.DataBindings.Add("Checked", vm, nameof(IMatrixJsonItemVM.ColumnsResizable));
    6797
    68       int rows = matrix.Length;
    69       int cols = matrix.Max(x => x.Length);
     98      int cols = matrix.Length;
     99      int rows = matrix.Max(x => x.Length);
    70100
    71101      Matrix = matrix;
     
    85115      int length = array.Length;
    86116
    87       Matrix = new T[array.Length][];
     117      Matrix = new T[1][];
     118      Matrix[0] = array;
     119      /*
    88120      for (int r = 0; r < length; ++r) {
    89121        Matrix[r] = new T[1];
    90122        Matrix[r][0] = array[r];
    91123      }
    92 
     124      */
    93125      _cols = 1;
    94126      _rows = length;
     
    125157
    126158      T[][] tmp = Matrix;
    127       Matrix = new T[Rows][];
     159      Matrix = new T[Columns][];
    128160
    129161      // columns must added first
    130       for(int c = 0; c < Columns; ++c) {
    131         dataGridView.Columns.Add($"Column {c}", $"Column {c}");
    132       }
    133 
    134       for (int r = 0; r < Rows; ++r) {
    135         T[] newCol = new T[Columns];
    136         if(r < tmp.Length)
    137           Array.Copy(tmp[r], 0, newCol, 0, Math.Min(tmp[r].Length, Columns));
    138         Matrix[r] = newCol;
     162      if(RowNames != null && RowNames.Count() == Columns) {
     163        foreach(var name in RowNames) {
     164          dataGridView.Columns.Add(name, name);
     165        }
     166      } else {
     167        for(int c = 0; c < Columns; ++c) {
     168          dataGridView.Columns.Add($"Column {c}", $"Column {c}");
     169        }
     170      }
     171
     172      for (int c = 0; c < Columns; ++c) {
     173        T[] newCol = new T[Rows];
     174        if(c < tmp.Length)
     175          Array.Copy(tmp[c], 0, newCol, 0, Math.Min(tmp[c].Length, Rows));
     176        Matrix[c] = newCol;
    139177      }
    140178
     
    144182          for (int r = 0; r < Rows; ++r) {
    145183            //col and row is switched for dataGridView
    146             dataGridView[c, r].Value = Matrix[r][c];
    147             dataGridView.Rows[r].HeaderCell.Value = $"Row {r}";
     184            dataGridView[c, r].Value = Matrix[c][r];
     185            if (ColumnNames != null && r < ColumnNames.Count())
     186              dataGridView.Rows[r].HeaderCell.Value = ColumnNames.ElementAt(r);
     187            else
     188              dataGridView.Rows[r].HeaderCell.Value = $"Row {r}";
    148189          }
    149190        }
     
    214255    private void DataGridView_CellEndEdit(object sender, DataGridViewCellEventArgs e) {
    215256      object val = dataGridView[e.ColumnIndex, e.RowIndex].Value;
    216       Matrix[e.RowIndex][e.ColumnIndex] = (T)Convert.ChangeType(val.ToString().Replace(",", "."),
     257      Matrix[e.ColumnIndex][e.RowIndex] = (T)Convert.ChangeType(val.ToString().Replace(",", "."),
    217258                                            typeof(T),
    218259                                            System.Globalization.CultureInfo.InvariantCulture);
    219       SaveCellData(Matrix[e.RowIndex][e.ColumnIndex], e.RowIndex, e.ColumnIndex);
     260      SaveCellData(Matrix[e.ColumnIndex][e.RowIndex], e.ColumnIndex, e.RowIndex);
    220261    }
    221262  }
Note: See TracChangeset for help on using the changeset viewer.