Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/12/13 12:20:25 (12 years ago)
Author:
sforsten
Message:

#2018:

  • added column names to the ValueTypeArray and StringArray
  • added batch update methods to IStringConvertibleArray similar to methods in IStringConvertibleMatrix
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/ImprovingStringConvertibleMatrix/HeuristicLab.Data.Views/3.3/StringConvertibleArrayView.cs

    r7984 r9308  
    2323using System.ComponentModel;
    2424using System.Drawing;
     25using System.Linq;
    2526using System.Text;
    2627using System.Windows.Forms;
    27 using HeuristicLab.Common;
    2828using HeuristicLab.MainForm;
    2929using HeuristicLab.MainForm.WindowsForms;
     
    5353
    5454    protected override void DeregisterContentEvents() {
    55       Content.ItemChanged -= new EventHandler<EventArgs<int>>(Content_ItemChanged);
     55      Content.ColumnNamesChanged -= new EventHandler(Content_ColumnNamesChanged);
    5656      Content.Reset -= new EventHandler(Content_Reset);
     57      Content.ItemsChanged -= new EventHandler<ArrayValuesChangedEventArgs>(Content_ItemsChanged);
    5758      base.DeregisterContentEvents();
    5859    }
     
    6061    protected override void RegisterContentEvents() {
    6162      base.RegisterContentEvents();
    62       Content.ItemChanged += new EventHandler<EventArgs<int>>(Content_ItemChanged);
     63      Content.ItemsChanged += new EventHandler<ArrayValuesChangedEventArgs>(Content_ItemsChanged);
    6364      Content.Reset += new EventHandler(Content_Reset);
     65      Content.ColumnNamesChanged -= new EventHandler(Content_ColumnNamesChanged);
    6466    }
    6567
     
    9496          dataGridView.Rows[i].Cells[0].Value = Content.GetValue(i);
    9597        }
     98
    9699        dataGridView.Columns[0].Width = dataGridView.Columns[0].GetPreferredWidth(DataGridViewAutoSizeColumnMode.AllCells, true);
    97100      }
     101      UpdateRowHeaders();
     102      dataGridView.AutoResizeRowHeadersWidth(DataGridViewRowHeadersWidthSizeMode.AutoSizeToDisplayedHeaders);
    98103      dataGridView.Enabled = true;
    99104    }
    100105
    101     private void Content_ItemChanged(object sender, EventArgs<int> e) {
     106    protected virtual void UpdateRowHeaders() {
     107      for (int i = 0; i < dataGridView.RowCount; i++) {
     108        if (i < Content.ColumnNames.Count())
     109          dataGridView.Rows[i].HeaderCell.Value = Content.ColumnNames.ElementAt(i);
     110        else
     111          dataGridView.Rows[i].HeaderCell.Value = "Column " + (i + 1);
     112      }
     113    }
     114
     115    private void Content_ItemsChanged(object sender, ArrayValuesChangedEventArgs e) {
    102116      if (InvokeRequired)
    103         Invoke(new EventHandler<EventArgs<int>>(Content_ItemChanged), sender, e);
     117        Invoke(new EventHandler<ArrayValuesChangedEventArgs>(Content_ItemsChanged), sender, e);
    104118      else {
    105         dataGridView.Rows[e.Value].Cells[0].Value = Content.GetValue(e.Value);
    106         Size size = dataGridView.Rows[e.Value].Cells[0].PreferredSize;
    107         dataGridView.Columns[0].Width = Math.Max(dataGridView.Columns[0].Width, size.Width);
    108       }
     119        foreach (var index in e.Value) {
     120          dataGridView.Rows[index].Cells[0].Value = Content.GetValue(index);
     121          Size size = dataGridView.Rows[index].Cells[0].PreferredSize;
     122          dataGridView.Columns[0].Width = Math.Max(dataGridView.Columns[0].Width, size.Width);
     123        }
     124      }
     125    }
     126    private void Content_ColumnNamesChanged(object sender, EventArgs e) {
     127      if (InvokeRequired)
     128        Invoke(new EventHandler(Content_ColumnNamesChanged), sender, e);
     129      else
     130        UpdateRowHeaders();
    109131    }
    110132    private void Content_Reset(object sender, EventArgs e) {
Note: See TracChangeset for help on using the changeset viewer.