Free cookie consent management tool by TermsFeed Policy Generator

Changeset 10585


Ignore:
Timestamp:
03/12/14 16:45:58 (10 years ago)
Author:
rstoll
Message:
  • Apply sort had unnecessary refresh - fixed
  • Refactored notOwnEvent - own method triggersOwnEvent for saver usage
File:
1 edited

Legend:

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

    r10583 r10585  
    2222using System;
    2323using System.Collections.Generic;
     24using System.Drawing;
    2425using System.Linq;
    2526using System.Windows.Forms;
    2627using HeuristicLab.MainForm;
    27 using System.Drawing;
    2828
    2929namespace HeuristicLab.DataPreprocessing.Views {
     
    4343
    4444    private IList<int> _highlightedRowIndices;
    45     public IList<int> highlightedRowIndices
    46     {
    47         get { return _highlightedRowIndices; }
    48         set
    49         {
    50             _highlightedRowIndices = value;
    51             Refresh();
    52         }
     45    public IList<int> highlightedRowIndices {
     46      get { return _highlightedRowIndices; }
     47      set {
     48        _highlightedRowIndices = value;
     49        Refresh();
     50      }
    5351    }
    5452
     
    5654      InitializeComponent();
    5755      dataGridView.CellMouseClick += dataGridView_CellMouseClick;
    58       dataGridView.CellPainting      += new System.Windows.Forms.DataGridViewCellPaintingEventHandler(dataGridView_CellPainting);
     56      dataGridView.CellPainting += new System.Windows.Forms.DataGridViewCellPaintingEventHandler(dataGridView_CellPainting);
    5957      contextMenuCell.Items.Add(ShowHideColumns);
    6058    }
     
    9290
    9391    protected override void dataGridView_CellParsing(object sender, DataGridViewCellParsingEventArgs e) {
    94       notOwnEvent = false;
    95       base.dataGridView_CellParsing(sender, e);
    96       notOwnEvent = true;
     92      triggersOwnEvent(() => base.dataGridView_CellParsing(sender, e));
    9793    }
    9894
    9995    protected override void PasteValuesToDataGridView() {
    100       notOwnEvent = false;
    101       base.PasteValuesToDataGridView();
    102       notOwnEvent = true;
     96      triggersOwnEvent(() => base.PasteValuesToDataGridView());
    10397    }
    104 
    10598
    10699    protected override void SetEnabledStateOfControls() {
     
    111104
    112105    private void btnApplySort_Click(object sender, System.EventArgs e) {
    113       Content.PreprocessingDataManipulation.ReOrderToIndices(virtualRowIndices);
    114       OnContentChanged();
     106      triggersOwnEvent(() => {
     107        Content.PreprocessingDataManipulation.ReOrderToIndices(virtualRowIndices);
     108        OnContentChanged();
     109      });
    115110    }
     111
     112    private void triggersOwnEvent(Action action) {
     113      notOwnEvent = false;
     114      action();
     115      notOwnEvent = true;
     116    }
     117
    116118
    117119    private void dataGridView_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e) {
     
    129131    }
    130132
    131     protected void dataGridView_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
    132     {
    133         if (Content == null) return;
    134         if (e.RowIndex < 0) return;
    135         if (e.ColumnIndex < 0) return;
    136         if (e.State.HasFlag(DataGridViewElementStates.Selected)) return;
    137         if (!e.PaintParts.HasFlag(DataGridViewPaintParts.Background)) return;
     133    protected void dataGridView_CellPainting(object sender, DataGridViewCellPaintingEventArgs e) {
     134      if (Content == null) return;
     135      if (e.RowIndex < 0) return;
     136      if (e.ColumnIndex < 0) return;
     137      if (e.State.HasFlag(DataGridViewElementStates.Selected)) return;
     138      if (!e.PaintParts.HasFlag(DataGridViewPaintParts.Background)) return;
    138139
    139         int rowIndex = virtualRowIndices[e.RowIndex];
     140      int rowIndex = virtualRowIndices[e.RowIndex];
    140141
    141         Color backColor = e.CellStyle.BackColor;
     142      Color backColor = e.CellStyle.BackColor;
    142143
    143         if (highlightedRowIndices != null && highlightedRowIndices.Contains(rowIndex))
    144         {
    145             backColor = Color.Pink;
    146         }
     144      if (highlightedRowIndices != null && highlightedRowIndices.Contains(rowIndex)) {
     145        backColor = Color.Pink;
     146      }
    147147
    148         using (Brush backColorBrush = new SolidBrush(backColor))
    149         {
    150             Rectangle bounds = new Rectangle(e.CellBounds.X, e.CellBounds.Y, e.CellBounds.Width, e.CellBounds.Height);
    151             e.Graphics.FillRectangle(backColorBrush, bounds);
    152         }
     148      using (Brush backColorBrush = new SolidBrush(backColor)) {
     149        Rectangle bounds = new Rectangle(e.CellBounds.X, e.CellBounds.Y, e.CellBounds.Width, e.CellBounds.Height);
     150        e.Graphics.FillRectangle(backColorBrush, bounds);
     151      }
    153152
    154         using (Brush gridBrush = new SolidBrush(Color.LightGray))
    155         {
    156             Pen gridLinePen = new Pen(gridBrush);
    157             e.Graphics.DrawLine(gridLinePen, e.CellBounds.Left,
    158                    e.CellBounds.Bottom - 1, e.CellBounds.Right - 1,
    159                    e.CellBounds.Bottom - 1);
    160             e.Graphics.DrawLine(gridLinePen, e.CellBounds.Right - 1,
    161                 e.CellBounds.Top, e.CellBounds.Right - 1,
    162                 e.CellBounds.Bottom);
    163         }
    164        
    165         e.PaintContent(e.CellBounds);
    166         e.Handled = true;
     153      using (Brush gridBrush = new SolidBrush(Color.LightGray)) {
     154        Pen gridLinePen = new Pen(gridBrush);
     155        e.Graphics.DrawLine(gridLinePen, e.CellBounds.Left,
     156               e.CellBounds.Bottom - 1, e.CellBounds.Right - 1,
     157               e.CellBounds.Bottom - 1);
     158        e.Graphics.DrawLine(gridLinePen, e.CellBounds.Right - 1,
     159            e.CellBounds.Top, e.CellBounds.Right - 1,
     160            e.CellBounds.Bottom);
     161      }
     162
     163      e.PaintContent(e.CellBounds);
     164      e.Handled = true;
    167165    }
    168166
Note: See TracChangeset for help on using the changeset viewer.