Free cookie consent management tool by TermsFeed Policy Generator

Changeset 4178


Ignore:
Timestamp:
08/09/10 15:34:47 (14 years ago)
Author:
mkommend
Message:

adapted the ColumnsVisibilityDialog and corrected copy and past support in the StringConvertibleMatrixView (ticket #1134)

Location:
trunk/sources/HeuristicLab.Data.Views/3.3
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Data.Views/3.3/ColumnsVisibilityDialog.Designer.cs

    r3742 r4178  
    4646    private void InitializeComponent() {
    4747      this.checkedListBox = new System.Windows.Forms.CheckedListBox();
     48      this.btnShowAll = new System.Windows.Forms.Button();
     49      this.btnHideAll = new System.Windows.Forms.Button();
    4850      this.SuspendLayout();
    4951      //
     
    5759      this.checkedListBox.Location = new System.Drawing.Point(12, 12);
    5860      this.checkedListBox.Name = "checkedListBox";
    59       this.checkedListBox.Size = new System.Drawing.Size(171, 244);
     61      this.checkedListBox.Size = new System.Drawing.Size(309, 289);
    6062      this.checkedListBox.TabIndex = 0;
    6163      this.checkedListBox.ItemCheck += new System.Windows.Forms.ItemCheckEventHandler(this.checkedListBox_ItemCheck);
     64      //
     65      // btnShowAll
     66      //
     67      this.btnShowAll.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
     68      this.btnShowAll.Location = new System.Drawing.Point(12, 315);
     69      this.btnShowAll.Name = "btnShowAll";
     70      this.btnShowAll.Size = new System.Drawing.Size(75, 23);
     71      this.btnShowAll.TabIndex = 1;
     72      this.btnShowAll.Text = "Show all";
     73      this.btnShowAll.UseVisualStyleBackColor = true;
     74      this.btnShowAll.Click += new System.EventHandler(this.btnShowAll_Click);
     75      //
     76      // btnHideAll
     77      //
     78      this.btnHideAll.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
     79      this.btnHideAll.Location = new System.Drawing.Point(101, 315);
     80      this.btnHideAll.Name = "btnHideAll";
     81      this.btnHideAll.Size = new System.Drawing.Size(75, 23);
     82      this.btnHideAll.TabIndex = 2;
     83      this.btnHideAll.Text = "Hide all";
     84      this.btnHideAll.UseVisualStyleBackColor = true;
     85      this.btnHideAll.Click += new System.EventHandler(this.btnHideAll_Click);
    6286      //
    6387      // ColumnsVisibilityDialog
     
    6589      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    6690      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    67       this.ClientSize = new System.Drawing.Size(194, 273);
     91      this.ClientSize = new System.Drawing.Size(332, 350);
     92      this.Controls.Add(this.btnHideAll);
     93      this.Controls.Add(this.btnShowAll);
    6894      this.Controls.Add(this.checkedListBox);
    6995      this.MaximizeBox = false;
     
    7298      this.ShowIcon = false;
    7399      this.ShowInTaskbar = false;
    74       this.Text = "Show / Hide Columns";
     100      this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
     101      this.Text = "Show/Hide Columns";
    75102      this.ResumeLayout(false);
    76103
     
    80107
    81108    private System.Windows.Forms.CheckedListBox checkedListBox;
     109    private System.Windows.Forms.Button btnShowAll;
     110    private System.Windows.Forms.Button btnHideAll;
    82111  }
    83112}
  • trunk/sources/HeuristicLab.Data.Views/3.3/ColumnsVisibilityDialog.cs

    r4068 r4178  
    5252      this.columns[e.Index].Visible = e.NewValue == CheckState.Checked;
    5353    }
     54
     55    private void btnShowAll_Click(object sender, System.EventArgs e) {
     56      for (int i = 0; i < checkedListBox.Items.Count; i++)
     57        checkedListBox.SetItemChecked(i, true);
     58    }
     59    private void btnHideAll_Click(object sender, System.EventArgs e) {
     60      for (int i = 0; i < checkedListBox.Items.Count; i++)
     61        checkedListBox.SetItemChecked(i, false);
     62    }
    5463  }
    5564}
  • trunk/sources/HeuristicLab.Data.Views/3.3/StringConvertibleMatrixView.Designer.cs

    r3936 r4178  
    7676      this.rowsTextBox.Size = new System.Drawing.Size(355, 20);
    7777      this.rowsTextBox.TabIndex = 1;
    78       this.rowsTextBox.Validated += new System.EventHandler(this.rowsTextBox_Validated);
    7978      this.rowsTextBox.KeyDown += new System.Windows.Forms.KeyEventHandler(this.rowsTextBox_KeyDown);
    8079      this.rowsTextBox.Validating += new System.ComponentModel.CancelEventHandler(this.rowsTextBox_Validating);
     80      this.rowsTextBox.Validated += new System.EventHandler(this.rowsTextBox_Validated);
    8181      //
    8282      // dataGridView
     
    8888                  | System.Windows.Forms.AnchorStyles.Left)
    8989                  | System.Windows.Forms.AnchorStyles.Right)));
     90      this.dataGridView.ClipboardCopyMode = System.Windows.Forms.DataGridViewClipboardCopyMode.Disable;
    9091      this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
    9192      this.dataGridView.Location = new System.Drawing.Point(0, 52);
     
    9596      this.dataGridView.TabIndex = 4;
    9697      this.dataGridView.VirtualMode = true;
    97       this.dataGridView.Scroll += new System.Windows.Forms.ScrollEventHandler(this.dataGridView_Scroll);
    98       this.dataGridView.ColumnHeaderMouseClick += new System.Windows.Forms.DataGridViewCellMouseEventHandler(this.dataGridView_ColumnHeaderMouseClick);
    99       this.dataGridView.CellValueNeeded += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.dataGridView_CellValueNeeded);
     98      this.dataGridView.CellEndEdit += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView_CellEndEdit);
    10099      this.dataGridView.CellParsing += new System.Windows.Forms.DataGridViewCellParsingEventHandler(this.dataGridView_CellParsing);
    101100      this.dataGridView.CellValidating += new System.Windows.Forms.DataGridViewCellValidatingEventHandler(this.dataGridView_CellValidating);
    102       this.dataGridView.CellEndEdit += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView_CellEndEdit);
     101      this.dataGridView.CellValueNeeded += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.dataGridView_CellValueNeeded);
     102      this.dataGridView.ColumnHeaderMouseClick += new System.Windows.Forms.DataGridViewCellMouseEventHandler(this.dataGridView_ColumnHeaderMouseClick);
     103      this.dataGridView.Scroll += new System.Windows.Forms.ScrollEventHandler(this.dataGridView_Scroll);
    103104      this.dataGridView.KeyDown += new System.Windows.Forms.KeyEventHandler(this.dataGridView_KeyDown);
    104105      this.dataGridView.Resize += new System.EventHandler(this.dataGridView_Resize);
     
    117118      this.columnsTextBox.Size = new System.Drawing.Size(355, 20);
    118119      this.columnsTextBox.TabIndex = 3;
    119       this.columnsTextBox.Validated += new System.EventHandler(this.columnsTextBox_Validated);
    120120      this.columnsTextBox.KeyDown += new System.Windows.Forms.KeyEventHandler(this.columnsTextBox_KeyDown);
    121121      this.columnsTextBox.Validating += new System.ComponentModel.CancelEventHandler(this.columnsTextBox_Validating);
     122      this.columnsTextBox.Validated += new System.EventHandler(this.columnsTextBox_Validated);
    122123      //
    123124      // columnsLabel
     
    162163
    163164    }
    164 
    165165    #endregion
    166166
  • trunk/sources/HeuristicLab.Data.Views/3.3/StringConvertibleMatrixView.cs

    r4068 r4178  
    2424using System.ComponentModel;
    2525using System.Linq;
     26using System.Text;
    2627using System.Windows.Forms;
    2728using HeuristicLab.Common;
     
    103104      columnsTextBox.Text = Content.Columns.ToString();
    104105      columnsTextBox.Enabled = true;
    105       //DataGridViews with Rows but no columns are not allowed !
     106      //DataGridViews with rows but no columns are not allowed !
    106107      if (Content.Rows == 0 && dataGridView.RowCount != Content.Rows && !Content.ReadOnly)
    107108        Content.Rows = dataGridView.RowCount;
     
    116117      UpdateColumnHeaders();
    117118      dataGridView.Enabled = true;
     119      dataGridView.AutoResizeRowHeadersWidth(DataGridViewRowHeadersWidthSizeMode.AutoSizeToDisplayedHeaders);
    118120    }
    119121
    120122    private void UpdateColumnHeaders() {
    121       int firstDisplayedColumnIndex = this.dataGridView.FirstDisplayedScrollingColumnIndex;
    122       if (firstDisplayedColumnIndex == -1)
    123         firstDisplayedColumnIndex = 0;
    124       int lastDisplayedColumnIndex = firstDisplayedColumnIndex + dataGridView.DisplayedColumnCount(true);
    125       for (int i = firstDisplayedColumnIndex; i < lastDisplayedColumnIndex; i++) {
     123      for (int i = 0; i < dataGridView.ColumnCount; i++) {
    126124        if (Content.ColumnNames.Count() != 0)
    127125          dataGridView.Columns[i].HeaderText = Content.ColumnNames.ElementAt(i);
     
    137135        firstDisplayedRowIndex = 0;
    138136      int lastDisplaydRowIndex = firstDisplayedRowIndex + dataGridView.DisplayedRowCount(true);
     137
    139138      for (int i = firstDisplayedRowIndex; i < lastDisplaydRowIndex; i++) {
    140139        if (Content.RowNames.Count() != 0)
     
    143142          dataGridView.Rows[i].HeaderCell.Value = "Row " + (i + 1);
    144143      }
    145       dataGridView.AutoResizeRowHeadersWidth(DataGridViewRowHeadersWidthSizeMode.AutoSizeToDisplayedHeaders);
    146144    }
    147145
     
    245243      }
    246244    }
    247     private void dataGridView_Scroll(object sender, ScrollEventArgs e) {
    248       UpdateRowHeaders();
    249       UpdateColumnHeaders();
     245
     246    private void dataGridView_Scroll(object sender, System.Windows.Forms.ScrollEventArgs e) {
     247      this.UpdateRowHeaders();
    250248    }
    251249    private void dataGridView_Resize(object sender, EventArgs e) {
    252       UpdateRowHeaders();
    253       UpdateColumnHeaders();
     250      this.UpdateRowHeaders();
    254251    }
    255252
    256253    private void dataGridView_KeyDown(object sender, KeyEventArgs e) {
    257       if (!ReadOnly && e.Control && e.KeyCode == Keys.V) { //shortcut for values paste
    258         string[,] values = SplitClipboardString(Clipboard.GetText());
    259 
    260         int rowIndex = 0;
    261         int columnIndex = 0;
    262         if (dataGridView.CurrentCell != null) {
    263           rowIndex = dataGridView.CurrentCell.RowIndex;
    264           columnIndex = dataGridView.CurrentCell.ColumnIndex;
    265         }
    266 
    267         for (int row = 0; row < values.GetLength(1); row++) {
    268           if (row + rowIndex >= Content.Rows)
    269             Content.Rows = Content.Rows + 1;
    270           for (int col = 0; col < values.GetLength(0); col++) {
    271             if (col + columnIndex >= Content.Columns)
    272               Content.Columns = Content.Columns + 1;
    273             Content.SetValue(values[col, row], row + rowIndex, col + columnIndex);
     254      if (!ReadOnly && e.Control && e.KeyCode == Keys.V)
     255        PasteValuesToDataGridView();
     256      else if (e.Control && e.KeyCode == Keys.C)
     257        CopyValuesFromDataGridView();
     258    }
     259
     260    private void CopyValuesFromDataGridView() {
     261      if (dataGridView.SelectedCells.Count == 0) return;
     262      StringBuilder s = new StringBuilder();
     263      int minRowIndex = dataGridView.SelectedCells[0].RowIndex;
     264      int maxRowIndex = dataGridView.SelectedCells[dataGridView.SelectedCells.Count - 1].RowIndex;
     265      int minColIndex = dataGridView.SelectedCells[0].ColumnIndex;
     266      int maxColIndex = dataGridView.SelectedCells[dataGridView.SelectedCells.Count - 1].ColumnIndex;
     267
     268      if (minRowIndex > maxRowIndex) {
     269        int temp = minRowIndex;
     270        minRowIndex = maxRowIndex;
     271        maxRowIndex = temp;
     272      }
     273      if (minColIndex > maxColIndex) {
     274        int temp = minColIndex;
     275        minColIndex = maxColIndex;
     276        maxColIndex = temp;
     277      }
     278
     279      bool addColumnNames = Content.ColumnNames.Any() && minRowIndex == 0;
     280      bool addRowNames = Content.RowNames.Any() && minColIndex == 0;
     281
     282      //add colum names
     283      if (addColumnNames) {
     284        if (addRowNames)
     285          s.Append('\t');
     286
     287        DataGridViewColumn column = dataGridView.Columns.GetFirstColumn(DataGridViewElementStates.Visible);
     288        while (column != null) {
     289          s.Append(column.HeaderText);
     290          s.Append('\t');
     291          column = dataGridView.Columns.GetNextColumn(column, DataGridViewElementStates.Visible, DataGridViewElementStates.None);
     292        }
     293        s.Remove(s.Length - 1, 1); //remove last tab
     294        s.Append(Environment.NewLine);
     295      }
     296
     297      for (int i = minRowIndex; i <= maxRowIndex; i++) {
     298        int rowIndex = this.virtualRowIndizes[i];
     299        if (addRowNames) {
     300          s.Append(Content.RowNames.ElementAt(rowIndex));
     301          s.Append('\t');
     302        }
     303
     304        DataGridViewColumn column = dataGridView.Columns.GetFirstColumn(DataGridViewElementStates.Visible);
     305        while (column != null) {
     306          DataGridViewCell cell = dataGridView[column.Index, i];
     307          if (cell.Selected) {
     308            s.Append(Content.GetValue(rowIndex, column.Index));
    274309          }
    275         }
    276 
    277         ClearSorting();
    278       }
    279     }
    280 
     310          s.Append('\t');
     311          column = dataGridView.Columns.GetNextColumn(column, DataGridViewElementStates.Visible, DataGridViewElementStates.None);
     312        }
     313        s.Remove(s.Length - 1, 1); //remove last tab
     314        s.Append(Environment.NewLine);
     315      }
     316      Clipboard.SetText(s.ToString());
     317    }
     318
     319    private void PasteValuesToDataGridView() {
     320      string[,] values = SplitClipboardString(Clipboard.GetText());
     321      int rowIndex = 0;
     322      int columnIndex = 0;
     323      if (dataGridView.CurrentCell != null) {
     324        rowIndex = dataGridView.CurrentCell.RowIndex;
     325        columnIndex = dataGridView.CurrentCell.ColumnIndex;
     326      }
     327
     328      for (int row = 0; row < values.GetLength(1); row++) {
     329        if (row + rowIndex >= Content.Rows)
     330          Content.Rows = Content.Rows + 1;
     331        for (int col = 0; col < values.GetLength(0); col++) {
     332          if (col + columnIndex >= Content.Columns)
     333            Content.Columns = Content.Columns + 1;
     334          Content.SetValue(values[col, row], row + rowIndex, col + columnIndex);
     335        }
     336      }
     337      ClearSorting();
     338    }
    281339    private string[,] SplitClipboardString(string clipboardText) {
    282340      clipboardText = clipboardText.Remove(clipboardText.Length - Environment.NewLine.Length);  //remove last newline constant
Note: See TracChangeset for help on using the changeset viewer.