Changeset 14723


Ignore:
Timestamp:
03/07/17 11:02:19 (8 months ago)
Author:
mkommend
Message:

#2709: Updated branch with most recent trunk changes.

Location:
branches/DataPreprocessing Enhancements
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/DataPreprocessing Enhancements/HeuristicLab.DataPreprocessing

  • branches/DataPreprocessing Enhancements/HeuristicLab.DataPreprocessing.Views

  • branches/DataPreprocessing Enhancements/HeuristicLab.DataPreprocessing.Views/3.4/DataGridContentView.cs

    r14583 r14723  
    5858    public DataGridContentView() {
    5959      InitializeComponent();
     60      dataGridView.MouseDown += dataGridView_MouseDown;
    6061      dataGridView.CellMouseClick += dataGridView_CellMouseClick;
    6162      dataGridView.RowHeaderMouseClick += dataGridView_RowHeaderMouseClick;
    62       dataGridView.KeyDown += dataGridView_KeyDown;
    6363      dataGridView.MouseUp += dataGridView_MouseUp;
    6464      contextMenuCell.Items.Add(ShowHideColumns);
     
    204204    }
    205205
     206    //Necessary so that dataGridView.SelectedRows and SelectedColumns are populated correctly
     207    //further information: https://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.selectedcolumns.aspx
     208    private void dataGridView_MouseDown(object sender, MouseEventArgs e) {
     209      var hitTestInfo = dataGridView.HitTest(e.X, e.Y);
     210      // row header click
     211      if (hitTestInfo.ColumnIndex == -1 && hitTestInfo.RowIndex >= 0) {
     212        if (dataGridView.SelectionMode != DataGridViewSelectionMode.RowHeaderSelect) {
     213          dataGridView.SelectionMode = DataGridViewSelectionMode.RowHeaderSelect;
     214        }
     215      }
     216      // column header click
     217      if (hitTestInfo.RowIndex == -1 && hitTestInfo.ColumnIndex >= 0) {
     218        if (dataGridView.SelectionMode != DataGridViewSelectionMode.ColumnHeaderSelect) {
     219          dataGridView.SelectionMode = DataGridViewSelectionMode.ColumnHeaderSelect;
     220        }
     221      }
     222    }
     223
    206224    protected override void dataGridView_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e) {
    207       if (Content != null) {
    208         if (e.Button == MouseButtons.Left) {
    209           dataGridView.Focus();
    210           dataGridView.ClearSelection();
    211           dataGridView.SelectionChanged -= dataGridView_SelectionChanged;
    212           for (int i = 0; i < dataGridView.RowCount; i++) {
    213             if (i + 1 == dataGridView.RowCount)
    214               dataGridView.SelectionChanged += dataGridView_SelectionChanged;
    215             dataGridView[e.ColumnIndex, i].Selected = true;
    216           }
    217         } else if (e.Button == MouseButtons.Middle) {
    218           int newIndex = e.ColumnIndex >= 0 ? e.ColumnIndex : 0;
    219           Content.PreProcessingData.InsertColumn<double>(newIndex.ToString(), newIndex);
    220         } else if (e.Button == MouseButtons.Right && Content.SortableView) {
    221           SortColumn(e.ColumnIndex);
    222         }
    223       }
     225      if (Content == null) return;
     226
     227      if (e.Button == MouseButtons.Middle) {
     228        int newIndex = e.ColumnIndex >= 0 ? e.ColumnIndex : 0;
     229        Content.PreProcessingData.InsertColumn<double>(newIndex.ToString(), newIndex);
     230      } else if (e.Button == MouseButtons.Right && Content.SortableView) {
     231        SortColumn(e.ColumnIndex);
     232      }
     233
    224234      searchIterator = null;
    225235    }
     
    538548
    539549    protected override void dataGridView_KeyDown(object sender, KeyEventArgs e) {
    540       var selectedRows = dataGridView.SelectedRows;
    541       var selectedCells = dataGridView.SelectedCells;
    542       if (!Content.FilterLogic.IsFiltered) { //data is in read only mode....
    543         if (e.KeyCode == Keys.Delete && selectedCells.Count == Content.Rows && selectedCells.Count > 0) {
    544           Content.DeleteColumn(selectedCells[0].ColumnIndex);
    545         } else if (e.KeyCode == Keys.Delete && selectedRows.Count > 0) {
    546           List<int> rows = new List<int>();
    547           for (int i = 0; i < selectedRows.Count; ++i) {
    548             int index = (sortedColumnIndices.Count != 0) ? (Convert.ToInt32(selectedRows[i].HeaderCell.Value) - 1) :
    549               selectedRows[i].Index;
    550             rows.Add(index);
    551           }
    552           Content.DeleteRows(rows);
    553         } else if (e.Control && e.KeyCode == Keys.F) {
    554           CreateFindAndReplaceDialog();
    555           findAndReplaceDialog.ActivateSearch();
    556         } else if (e.Control && e.KeyCode == Keys.R) {
    557           CreateFindAndReplaceDialog();
    558           findAndReplaceDialog.ActivateReplace();
    559         }
     550      base.dataGridView_KeyDown(sender, e);
     551      //data is in read only mode....
     552      if (Content.FilterLogic.IsFiltered) return;
     553
     554      if (e.KeyCode == Keys.Delete) {
     555        //Delete column
     556        if (dataGridView.SelectedColumns.Count > 0) {
     557          var columnsToDelete = dataGridView.SelectedColumns.Cast<DataGridViewColumn>().OrderByDescending(col => col.Index).ToList();
     558          foreach (var col in columnsToDelete)
     559            Content.DeleteColumn(col.Index);
     560        }
     561        //Delete row
     562        if (dataGridView.SelectedRows.Count > 0) {
     563          //necessary if columns are sorted to translate the selected row index
     564          var rowIndexes = dataGridView.SelectedRows.Cast<DataGridViewRow>().Select(row => GetRowIndex(row.Index)).ToList();
     565          Content.DeleteRows(rowIndexes);
     566        }
     567      } else if (e.Control && e.KeyCode == Keys.F) {
     568        CreateFindAndReplaceDialog();
     569        findAndReplaceDialog.ActivateSearch();
     570      } else if (e.Control && e.KeyCode == Keys.R) {
     571        CreateFindAndReplaceDialog();
     572        findAndReplaceDialog.ActivateReplace();
    560573      }
    561574    }
Note: See TracChangeset for help on using the changeset viewer.