Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/12/14 17:42:42 (11 years ago)
Author:
sbreuer
Message:
  • enhanced selection of cells
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.3/DataGridContentView.cs

    r10585 r10590  
    2222using System;
    2323using System.Collections.Generic;
    24 using System.Drawing;
    2524using System.Linq;
    2625using System.Windows.Forms;
     26using HeuristicLab.Data.Views;
    2727using HeuristicLab.MainForm;
     28using System.Drawing;
    2829
    2930namespace HeuristicLab.DataPreprocessing.Views {
     
    3132  [Content(typeof(IDataGridContent), true)]
    3233  public partial class DataGridContentView : CopyOfStringConvertibleMatrixView {
    33 
    34     private int lastClickedRow;
    35     private int lastClickedColumn;
    3634
    3735    private bool notOwnEvent = true;
     
    123121          contextMenu.Show(MousePosition);
    124122        } else {
     123          if (!dataGridView.SelectedCells.Contains(dataGridView[e.ColumnIndex, e.RowIndex])) {
     124            dataGridView.ClearSelection();
     125            dataGridView[e.ColumnIndex, e.RowIndex].Selected = true;
     126          }
    125127          interpolationToolStripMenuItem.Enabled = !(e.RowIndex == 0 || e.RowIndex == Content.Rows);
    126128          contextMenuCell.Show(MousePosition);
    127           lastClickedColumn = e.ColumnIndex;
    128           lastClickedRow = e.RowIndex;
    129129        }
    130130      }
     
    175175    }
    176176
     177    private Dictionary<int, List<int>> GetSelectedCells() {
     178      var selectedCells = new Dictionary<int, List<int>>();
     179      for (int i = 0; i < dataGridView.SelectedCells.Count; i++) {
     180        var columnIndex=dataGridView.SelectedCells[i].ColumnIndex;
     181        if(!selectedCells.ContainsKey(columnIndex)){
     182          selectedCells.Add(columnIndex,new List<int>());
     183        }
     184        selectedCells[columnIndex].Add(dataGridView.SelectedCells[i].RowIndex);
     185      }
     186      return selectedCells;
     187    }
     188
    177189    private void ReplaceWithAverage_Click(object sender, EventArgs e) {
    178       Content.PreprocessingDataManipulation.ReplaceIndicesByAverageValue(lastClickedColumn, new List<int>() { lastClickedRow });
     190      Content.PreprocessingDataManipulation.ReplaceIndicesByAverageValue(GetSelectedCells());
    179191    }
    180192
    181193    private void ReplaceWithMedian_Click(object sender, EventArgs e) {
    182       Content.PreprocessingDataManipulation.ReplaceIndicesByMedianValue(lastClickedColumn, new List<int>() { lastClickedRow });
     194      Content.PreprocessingDataManipulation.ReplaceIndicesByMedianValue(GetSelectedCells());
    183195    }
    184196
    185197    private void ReplaceWithRandom_Click(object sender, EventArgs e) {
    186       Content.PreprocessingDataManipulation.ReplaceIndicesByRandomValue(lastClickedColumn, new List<int>() { lastClickedRow });
     198      Content.PreprocessingDataManipulation.ReplaceIndicesByRandomValue(GetSelectedCells());
    187199    }
    188200
    189201    private void ReplaceWithMostCommon_Click(object sender, EventArgs e) {
    190       Content.PreprocessingDataManipulation.ReplaceIndicesByMostCommonValue(lastClickedColumn, new List<int>() { lastClickedRow });
     202      Content.PreprocessingDataManipulation.ReplaceIndicesByMostCommonValue(GetSelectedCells());
    191203    }
    192204
    193205    private void ReplaceWithInterpolation_Click(object sender, EventArgs e) {
    194       Content.PreprocessingDataManipulation.ReplaceIndicesByLinearInterpolationOfNeighbours(lastClickedColumn, new List<int>() { lastClickedRow });
     206      Content.PreprocessingDataManipulation.ReplaceIndicesByLinearInterpolationOfNeighbours(GetSelectedCells());
    195207    }
    196208  }
Note: See TracChangeset for help on using the changeset viewer.