Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.4/CopyOfStringConvertibleMatrixView.cs @ 10925

Last change on this file since 10925 was 10916, checked in by rstoll, 10 years ago
  • Fixed FindAll -> selection was very slow, CopyOfStringConvertibleMatrix had registered an event as well which slowed down everything (more or less)
File size: 24.2 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.ComponentModel;
25using System.Drawing;
26using System.Linq;
27using System.Text;
28using System.Windows.Forms;
29using HeuristicLab.Common;
30using HeuristicLab.Data;
31using HeuristicLab.Data.Views;
32using HeuristicLab.MainForm;
33using HeuristicLab.MainForm.WindowsForms;
34
35namespace HeuristicLab.DataPreprocessing.Views {
36  [View("StringConvertibleMatrix View")]
37  [Content(typeof(IStringConvertibleMatrix), false)]
38  public partial class CopyOfStringConvertibleMatrixView : AsynchronousContentView {
39
40    // Was private before
41    protected virtual void dataGridView_CellValidating(object sender, DataGridViewCellValidatingEventArgs e) {
42      if (!dataGridView.ReadOnly) {
43        string errorMessage;
44        if (Content != null && !Content.Validate(e.FormattedValue.ToString(), out errorMessage)) {
45          e.Cancel = true;
46          dataGridView.Rows[e.RowIndex].ErrorText = errorMessage;
47        }
48      }
49    }
50
51    // Was private before
52    protected virtual void dataGridView_CellParsing(object sender, DataGridViewCellParsingEventArgs e) {
53      if (!dataGridView.ReadOnly) {
54        string value = e.Value.ToString();
55        int rowIndex = virtualRowIndices[e.RowIndex];
56        e.ParsingApplied = Content.SetValue(value, rowIndex, e.ColumnIndex);
57        if (e.ParsingApplied) e.Value = Content.GetValue(rowIndex, e.ColumnIndex);
58      }
59    }
60
61    // Was private before
62    protected virtual void PasteValuesToDataGridView() {
63      string[,] values = SplitClipboardString(Clipboard.GetText());
64      int rowIndex = 0;
65      int columnIndex = 0;
66      if (dataGridView.CurrentCell != null) {
67        rowIndex = dataGridView.CurrentCell.RowIndex;
68        columnIndex = dataGridView.CurrentCell.ColumnIndex;
69      }
70      if (Content.Rows < values.GetLength(1) + rowIndex) Content.Rows = values.GetLength(1) + rowIndex;
71      if (Content.Columns < values.GetLength(0) + columnIndex) Content.Columns = values.GetLength(0) + columnIndex;
72
73      for (int row = 0; row < values.GetLength(1); row++) {
74        for (int col = 0; col < values.GetLength(0); col++) {
75          Content.SetValue(values[col, row], row + rowIndex, col + columnIndex);
76        }
77      }
78      ClearSorting();
79    }
80
81    // Was private before
82    protected virtual void dataGridView_SelectionChanged(object sender, EventArgs e) {
83      string stringFormat = "{0,20:0.0000}";
84      statisticsTextBox.Text = string.Empty;
85      if (dataGridView.SelectedCells.Count > 1) {
86        List<double> selectedValues = new List<double>();
87        foreach (DataGridViewCell cell in dataGridView.SelectedCells) {
88          double value;
89          if (!double.TryParse(cell.Value.ToString(), out value)) return;
90          selectedValues.Add(value);
91        }
92        if (selectedValues.Count > 1) {
93          StringBuilder labelText = new StringBuilder();
94          labelText.Append("Count: " + string.Format(stringFormat, selectedValues.Count) + "    ");
95          labelText.Append("Sum: " + string.Format(stringFormat, selectedValues.Sum()) + "    ");
96          labelText.Append("Min: " + string.Format(stringFormat, selectedValues.Min()) + "    ");
97          labelText.Append("Max: " + string.Format(stringFormat, selectedValues.Max()) + "    ");
98          labelText.Append("Average: " + string.Format(stringFormat, selectedValues.Average()) + "    ");
99          labelText.Append("Standard Deviation: " + string.Format(stringFormat, selectedValues.StandardDeviation()) + "    ");
100
101          statisticsTextBox.Text = labelText.ToString();
102        }
103      }
104    }
105
106    #region unchanged copied from original - see  HeuristicLab.Data.Views.StringConvertibleMatrix
107
108    protected int[] virtualRowIndices;
109    private List<KeyValuePair<int, SortOrder>> sortedColumnIndices;
110    private RowComparer rowComparer;
111
112    public new IStringConvertibleMatrix Content {
113      get { return (IStringConvertibleMatrix)base.Content; }
114      set { base.Content = value; }
115    }
116
117    public DataGridView DataGridView {
118      get { return dataGridView; }
119    }
120
121    public override bool ReadOnly {
122      get {
123        if ((Content != null) && Content.ReadOnly) return true;
124        return base.ReadOnly;
125      }
126      set { base.ReadOnly = value; }
127    }
128
129    private bool showRowsAndColumnsTextBox;
130    public bool ShowRowsAndColumnsTextBox {
131      get { return showRowsAndColumnsTextBox; }
132      set {
133        showRowsAndColumnsTextBox = value;
134        UpdateVisibilityOfTextBoxes();
135      }
136    }
137
138    private bool showStatisticalInformation;
139    public bool ShowStatisticalInformation {
140      get { return showStatisticalInformation; }
141      set {
142        showStatisticalInformation = value;
143        UpdateVisibilityOfStatisticalInformation();
144      }
145    }
146
147    public CopyOfStringConvertibleMatrixView() {
148      InitializeComponent();
149      ShowRowsAndColumnsTextBox = true;
150      ShowStatisticalInformation = true;
151      errorProvider.SetIconAlignment(rowsTextBox, ErrorIconAlignment.MiddleLeft);
152      errorProvider.SetIconPadding(rowsTextBox, 2);
153      errorProvider.SetIconAlignment(columnsTextBox, ErrorIconAlignment.MiddleLeft);
154      errorProvider.SetIconPadding(columnsTextBox, 2);
155      sortedColumnIndices = new List<KeyValuePair<int, SortOrder>>();
156      rowComparer = new RowComparer();
157    }
158
159    protected override void DeregisterContentEvents() {
160      Content.ItemChanged -= new EventHandler<EventArgs<int, int>>(Content_ItemChanged);
161      Content.Reset -= new EventHandler(Content_Reset);
162      Content.ColumnNamesChanged -= new EventHandler(Content_ColumnNamesChanged);
163      Content.RowNamesChanged -= new EventHandler(Content_RowNamesChanged);
164      base.DeregisterContentEvents();
165    }
166    protected override void RegisterContentEvents() {
167      base.RegisterContentEvents();
168      Content.ItemChanged += new EventHandler<EventArgs<int, int>>(Content_ItemChanged);
169      Content.Reset += new EventHandler(Content_Reset);
170      Content.ColumnNamesChanged += new EventHandler(Content_ColumnNamesChanged);
171      Content.RowNamesChanged += new EventHandler(Content_RowNamesChanged);
172    }
173
174    protected override void OnContentChanged() {
175      base.OnContentChanged();
176      if (Content == null) {
177        rowsTextBox.Text = "";
178        columnsTextBox.Text = "";
179        dataGridView.Rows.Clear();
180        dataGridView.Columns.Clear();
181        virtualRowIndices = new int[0];
182      } else
183        UpdateData();
184    }
185
186    protected override void SetEnabledStateOfControls() {
187      base.SetEnabledStateOfControls();
188      rowsTextBox.Enabled = Content != null;
189      columnsTextBox.Enabled = Content != null;
190      dataGridView.Enabled = Content != null;
191      rowsTextBox.ReadOnly = ReadOnly;
192      columnsTextBox.ReadOnly = ReadOnly;
193      dataGridView.ReadOnly = ReadOnly;
194    }
195
196    private void UpdateData() {
197
198      Point[] selectedCellsBeforeUpdate = GetSelectedCellsAsPoints();
199
200      rowsTextBox.Text = Content.Rows.ToString();
201      rowsTextBox.Enabled = true;
202      columnsTextBox.Text = Content.Columns.ToString();
203      columnsTextBox.Enabled = true;
204      virtualRowIndices = Enumerable.Range(0, Content.Rows).ToArray();
205
206      if (Content.Columns == 0 && dataGridView.ColumnCount != Content.Columns && !Content.ReadOnly)
207        Content.Columns = dataGridView.ColumnCount;
208      else {
209        DataGridViewColumn[] columns = new DataGridViewColumn[Content.Columns];
210        for (int i = 0; i < columns.Length; ++i) {
211          var column = new DataGridViewTextBoxColumn();
212          column.FillWeight = 1;
213          columns[i] = column;
214        }
215        dataGridView.Columns.Clear();
216        dataGridView.Columns.AddRange(columns);
217      }
218
219      //DataGridViews with rows but no columns are not allowed !
220      if (Content.Rows == 0 && dataGridView.RowCount != Content.Rows && !Content.ReadOnly)
221        Content.Rows = dataGridView.RowCount;
222      else
223        dataGridView.RowCount = Content.Rows;
224
225      ClearSorting();
226      UpdateColumnHeaders();
227      UpdateRowHeaders();
228
229      dataGridView.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.DisplayedCells);
230      dataGridView.AutoResizeRowHeadersWidth(DataGridViewRowHeadersWidthSizeMode.AutoSizeToDisplayedHeaders);
231      dataGridView.Enabled = true;
232
233
234      dataGridView.CurrentCell = null;
235      foreach (Point p in selectedCellsBeforeUpdate)
236        dataGridView[p.X, p.Y].Selected = true;
237    }
238
239    protected virtual void UpdateColumnHeaders() {
240      HashSet<string> invisibleColumnNames = new HashSet<string>(dataGridView.Columns.OfType<DataGridViewColumn>()
241      .Where(c => !c.Visible && !string.IsNullOrEmpty(c.HeaderText)).Select(c => c.HeaderText));
242
243      for (int i = 0; i < dataGridView.ColumnCount; i++) {
244        if (i < Content.ColumnNames.Count())
245          dataGridView.Columns[i].HeaderText = Content.ColumnNames.ElementAt(i);
246        else
247          dataGridView.Columns[i].HeaderText = "Column " + (i + 1);
248        dataGridView.Columns[i].Visible = !invisibleColumnNames.Contains(dataGridView.Columns[i].HeaderText);
249      }
250    }
251    protected virtual void UpdateRowHeaders() {
252      int index = dataGridView.FirstDisplayedScrollingRowIndex;
253      if (index == -1) index = 0;
254      int updatedRows = 0;
255      int count = dataGridView.DisplayedRowCount(true);
256
257      while (updatedRows < count) {
258        if (virtualRowIndices[index] < Content.RowNames.Count())
259          dataGridView.Rows[index].HeaderCell.Value = Content.RowNames.ElementAt(virtualRowIndices[index]);
260        else
261          dataGridView.Rows[index].HeaderCell.Value = "Row " + (index + 1);
262        if (dataGridView.Rows[index].Visible)
263          updatedRows++;
264        index++;
265      }
266    }
267
268    private void Content_RowNamesChanged(object sender, EventArgs e) {
269      if (InvokeRequired)
270        Invoke(new EventHandler(Content_RowNamesChanged), sender, e);
271      else
272        UpdateRowHeaders();
273    }
274    private void Content_ColumnNamesChanged(object sender, EventArgs e) {
275      if (InvokeRequired)
276        Invoke(new EventHandler(Content_ColumnNamesChanged), sender, e);
277      else
278        UpdateColumnHeaders();
279    }
280    private void Content_ItemChanged(object sender, EventArgs<int, int> e) {
281      if (InvokeRequired)
282        Invoke(new EventHandler<EventArgs<int, int>>(Content_ItemChanged), sender, e);
283      else
284        dataGridView.InvalidateCell(e.Value2, e.Value);
285    }
286    private void Content_Reset(object sender, EventArgs e) {
287      if (InvokeRequired)
288        Invoke(new EventHandler(Content_Reset), sender, e);
289      else
290        UpdateData();
291    }
292
293    private Point[] GetSelectedCellsAsPoints() {
294      Point[] points = new Point[dataGridView.SelectedCells.Count];
295      for (int i = 0; i < dataGridView.SelectedCells.Count; i++)
296      {
297        points[i].X = dataGridView.SelectedCells[i].ColumnIndex;
298        points[i].Y = dataGridView.SelectedCells[i].RowIndex;
299      }
300
301      return points;
302    }
303
304    #region TextBox Events
305    private void rowsTextBox_Validating(object sender, CancelEventArgs e) {
306      if (ReadOnly || Locked)
307        return;
308      int i = 0;
309      if (!int.TryParse(rowsTextBox.Text, out i) || (i <= 0)) {
310        e.Cancel = true;
311        errorProvider.SetError(rowsTextBox, "Invalid Number of Rows (Valid values are positive integers larger than 0)");
312        rowsTextBox.SelectAll();
313      }
314    }
315    private void rowsTextBox_Validated(object sender, EventArgs e) {
316      if (!Content.ReadOnly) Content.Rows = int.Parse(rowsTextBox.Text);
317      errorProvider.SetError(rowsTextBox, string.Empty);
318    }
319    private void rowsTextBox_KeyDown(object sender, KeyEventArgs e) {
320      if (e.KeyCode == Keys.Enter || e.KeyCode == Keys.Return)
321        rowsLabel.Focus();  // set focus on label to validate data
322      if (e.KeyCode == Keys.Escape) {
323        rowsTextBox.Text = Content.Rows.ToString();
324        rowsLabel.Focus();  // set focus on label to validate data
325      }
326    }
327    private void columnsTextBox_Validating(object sender, CancelEventArgs e) {
328      if (ReadOnly || Locked)
329        return;
330      int i = 0;
331      if (!int.TryParse(columnsTextBox.Text, out i) || (i <= 0)) {
332        e.Cancel = true;
333        errorProvider.SetError(columnsTextBox, "Invalid Number of Columns (Valid values are positive integers larger than 0)");
334        columnsTextBox.SelectAll();
335      }
336    }
337    private void columnsTextBox_Validated(object sender, EventArgs e) {
338      if (!Content.ReadOnly) Content.Columns = int.Parse(columnsTextBox.Text);
339      errorProvider.SetError(columnsTextBox, string.Empty);
340    }
341    private void columnsTextBox_KeyDown(object sender, KeyEventArgs e) {
342      if (e.KeyCode == Keys.Enter || e.KeyCode == Keys.Return)
343        columnsLabel.Focus();  // set focus on label to validate data
344      if (e.KeyCode == Keys.Escape) {
345        columnsTextBox.Text = Content.Columns.ToString();
346        columnsLabel.Focus();  // set focus on label to validate data
347      }
348    }
349    #endregion
350
351    #region DataGridView Events
352
353    private void dataGridView_CellEndEdit(object sender, DataGridViewCellEventArgs e) {
354      dataGridView.Rows[e.RowIndex].ErrorText = string.Empty;
355    }
356    private void dataGridView_CellValueNeeded(object sender, DataGridViewCellValueEventArgs e) {
357      if (Content != null && e.RowIndex < Content.Rows && e.ColumnIndex < Content.Columns) {
358        int rowIndex = virtualRowIndices[e.RowIndex];
359        e.Value = Content.GetValue(rowIndex, e.ColumnIndex);
360      }
361    }
362
363    private void dataGridView_Scroll(object sender, System.Windows.Forms.ScrollEventArgs e) {
364      this.UpdateRowHeaders();
365    }
366    private void dataGridView_Resize(object sender, EventArgs e) {
367      this.UpdateRowHeaders();
368    }
369
370    private void dataGridView_KeyDown(object sender, KeyEventArgs e) {
371      if (!ReadOnly && e.Control && e.KeyCode == Keys.V)
372        PasteValuesToDataGridView();
373      else if (e.Control && e.KeyCode == Keys.C)
374        CopyValuesFromDataGridView();
375    }
376
377    private void CopyValuesFromDataGridView() {
378      if (dataGridView.SelectedCells.Count == 0) return;
379      StringBuilder s = new StringBuilder();
380      int minRowIndex = dataGridView.SelectedCells[0].RowIndex;
381      int maxRowIndex = dataGridView.SelectedCells[dataGridView.SelectedCells.Count - 1].RowIndex;
382      int minColIndex = dataGridView.SelectedCells[0].ColumnIndex;
383      int maxColIndex = dataGridView.SelectedCells[dataGridView.SelectedCells.Count - 1].ColumnIndex;
384
385      if (minRowIndex > maxRowIndex) {
386        int temp = minRowIndex;
387        minRowIndex = maxRowIndex;
388        maxRowIndex = temp;
389      }
390      if (minColIndex > maxColIndex) {
391        int temp = minColIndex;
392        minColIndex = maxColIndex;
393        maxColIndex = temp;
394      }
395
396      bool addRowNames = dataGridView.AreAllCellsSelected(false) && Content.RowNames.Count() > 0;
397      bool addColumnNames = dataGridView.AreAllCellsSelected(false) && Content.ColumnNames.Count() > 0;
398
399      //add colum names
400      if (addColumnNames) {
401        if (addRowNames)
402          s.Append('\t');
403
404        DataGridViewColumn column = dataGridView.Columns.GetFirstColumn(DataGridViewElementStates.Visible);
405        while (column != null) {
406          s.Append(column.HeaderText);
407          s.Append('\t');
408          column = dataGridView.Columns.GetNextColumn(column, DataGridViewElementStates.Visible, DataGridViewElementStates.None);
409        }
410        s.Remove(s.Length - 1, 1); //remove last tab
411        s.Append(Environment.NewLine);
412      }
413
414      for (int i = minRowIndex; i <= maxRowIndex; i++) {
415        if (!dataGridView.Rows[i].Visible) continue;
416
417        int rowIndex = this.virtualRowIndices[i];
418        if (addRowNames) {
419          s.Append(Content.RowNames.ElementAt(rowIndex));
420          s.Append('\t');
421        }
422
423        DataGridViewColumn column = dataGridView.Columns.GetFirstColumn(DataGridViewElementStates.Visible);
424        while (column != null) {
425          DataGridViewCell cell = dataGridView[column.Index, i];
426          if (cell.Selected) {
427            s.Append(Content.GetValue(rowIndex, column.Index));
428            s.Append('\t');
429          }
430
431          column = dataGridView.Columns.GetNextColumn(column, DataGridViewElementStates.Visible, DataGridViewElementStates.None);
432        }
433        s.Remove(s.Length - 1, 1); //remove last tab
434        s.Append(Environment.NewLine);
435      }
436      Clipboard.SetText(s.ToString());
437    }
438
439    private string[,] SplitClipboardString(string clipboardText) {
440      if (clipboardText.EndsWith(Environment.NewLine))
441        clipboardText = clipboardText.Remove(clipboardText.Length - Environment.NewLine.Length);  //remove last newline constant
442      string[,] values = null;
443      string[] lines = clipboardText.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
444      string[] cells;
445      for (int i = 0; i < lines.Length; i++) {
446        cells = lines[i].Split('\t');
447        if (values == null)
448          values = new string[cells.Length, lines.Length];
449        for (int j = 0; j < cells.Length; j++)
450          values[j, i] = string.IsNullOrEmpty(cells[j]) ? string.Empty : cells[j];
451      }
452      return values;
453    }
454
455    private void dataGridView_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e) {
456      if (Content != null) {
457        if (e.Button == MouseButtons.Left && Content.SortableView) {
458          bool addToSortedIndices = (Control.ModifierKeys & Keys.Control) == Keys.Control;
459          SortOrder newSortOrder = SortOrder.Ascending;
460          if (sortedColumnIndices.Any(x => x.Key == e.ColumnIndex)) {
461            SortOrder oldSortOrder = sortedColumnIndices.Where(x => x.Key == e.ColumnIndex).First().Value;
462            int enumLength = Enum.GetValues(typeof(SortOrder)).Length;
463            newSortOrder = oldSortOrder = (SortOrder)Enum.Parse(typeof(SortOrder), ((((int)oldSortOrder) + 1) % enumLength).ToString());
464          }
465
466          if (!addToSortedIndices)
467            sortedColumnIndices.Clear();
468
469          if (sortedColumnIndices.Any(x => x.Key == e.ColumnIndex)) {
470            int sortedIndex = sortedColumnIndices.FindIndex(x => x.Key == e.ColumnIndex);
471            if (newSortOrder != SortOrder.None)
472              sortedColumnIndices[sortedIndex] = new KeyValuePair<int, SortOrder>(e.ColumnIndex, newSortOrder);
473            else
474              sortedColumnIndices.RemoveAt(sortedIndex);
475          } else
476            if (newSortOrder != SortOrder.None)
477              sortedColumnIndices.Add(new KeyValuePair<int, SortOrder>(e.ColumnIndex, newSortOrder));
478          Sort();
479        }
480      }
481    }
482
483    protected virtual void ClearSorting() {
484      virtualRowIndices = Enumerable.Range(0, Content.Rows).ToArray();
485      sortedColumnIndices.Clear();
486      UpdateSortGlyph();
487    }
488
489    private void Sort() {
490      virtualRowIndices = Sort(sortedColumnIndices);
491      UpdateSortGlyph();
492      UpdateRowHeaders();
493      dataGridView.Invalidate();
494    }
495    protected virtual int[] Sort(IEnumerable<KeyValuePair<int, SortOrder>> sortedColumns) {
496      int[] newSortedIndex = Enumerable.Range(0, Content.Rows).ToArray();
497      if (sortedColumns.Count() != 0) {
498        rowComparer.SortedIndices = sortedColumns;
499        rowComparer.Matrix = Content;
500        Array.Sort(newSortedIndex, rowComparer);
501      }
502      return newSortedIndex;
503    }
504    private void UpdateSortGlyph() {
505      foreach (DataGridViewColumn col in this.dataGridView.Columns)
506        col.HeaderCell.SortGlyphDirection = SortOrder.None;
507      foreach (KeyValuePair<int, SortOrder> p in sortedColumnIndices)
508        this.dataGridView.Columns[p.Key].HeaderCell.SortGlyphDirection = p.Value;
509    }
510    #endregion
511
512    public int GetRowIndex(int originalIndex) {
513      return virtualRowIndices[originalIndex];
514    }
515
516    public class RowComparer : IComparer<int> {
517      public RowComparer() {
518      }
519
520      private List<KeyValuePair<int, SortOrder>> sortedIndices;
521      public IEnumerable<KeyValuePair<int, SortOrder>> SortedIndices {
522        get { return this.sortedIndices; }
523        set { sortedIndices = new List<KeyValuePair<int, SortOrder>>(value); }
524      }
525      private IStringConvertibleMatrix matrix;
526      public IStringConvertibleMatrix Matrix {
527        get { return this.matrix; }
528        set { this.matrix = value; }
529      }
530
531      public int Compare(int x, int y) {
532        int result = 0;
533        double double1, double2;
534        DateTime dateTime1, dateTime2;
535        TimeSpan timeSpan1, timeSpan2;
536        string string1, string2;
537
538        if (matrix == null)
539          throw new InvalidOperationException("Could not sort IStringConvertibleMatrix if the matrix member is null.");
540        if (sortedIndices == null)
541          return 0;
542
543        foreach (KeyValuePair<int, SortOrder> pair in sortedIndices.Where(p => p.Value != SortOrder.None)) {
544          string1 = matrix.GetValue(x, pair.Key);
545          string2 = matrix.GetValue(y, pair.Key);
546          if (double.TryParse(string1, out double1) && double.TryParse(string2, out double2))
547            result = double1.CompareTo(double2);
548          else if (DateTime.TryParse(string1, out dateTime1) && DateTime.TryParse(string2, out dateTime2))
549            result = dateTime1.CompareTo(dateTime2);
550          else if (TimeSpan.TryParse(string1, out timeSpan1) && TimeSpan.TryParse(string2, out timeSpan2))
551            result = timeSpan1.CompareTo(timeSpan2);
552          else {
553            if (string1 != null)
554              result = string1.CompareTo(string2);
555            else if (string2 != null)
556              result = string2.CompareTo(string1) * -1;
557          }
558          if (pair.Value == SortOrder.Descending)
559            result *= -1;
560          if (result != 0)
561            return result;
562        }
563        return result;
564      }
565    }
566
567    private void dataGridView_MouseClick(object sender, System.Windows.Forms.MouseEventArgs e) {
568      if (Content == null) return;
569      if (e.Button == MouseButtons.Right && Content.ColumnNames.Count() != 0)
570        contextMenu.Show(MousePosition);
571    }
572    protected virtual void ShowHideColumns_Click(object sender, EventArgs e) {
573      new StringConvertibleMatrixColumnVisibilityDialog(this.dataGridView.Columns.Cast<DataGridViewColumn>()).ShowDialog();
574      columnsTextBox.Text = dataGridView.Columns.GetColumnCount(DataGridViewElementStates.Visible).ToString();
575    }
576
577    private void UpdateVisibilityOfTextBoxes() {
578      rowsTextBox.Visible = columnsTextBox.Visible = showRowsAndColumnsTextBox;
579      rowsLabel.Visible = columnsLabel.Visible = showRowsAndColumnsTextBox;
580      UpdateDataGridViewSizeAndLocation();
581    }
582
583    private void UpdateVisibilityOfStatisticalInformation() {
584      statisticsTextBox.Visible = showStatisticalInformation;
585      UpdateDataGridViewSizeAndLocation();
586    }
587
588    private void UpdateDataGridViewSizeAndLocation() {
589      int headerSize = columnsTextBox.Location.Y + columnsTextBox.Size.Height +
590       columnsTextBox.Margin.Bottom + dataGridView.Margin.Top;
591
592      int offset = showRowsAndColumnsTextBox ? headerSize : 0;
593      dataGridView.Location = new Point(0, offset);
594
595      int statisticsTextBoxHeight = showStatisticalInformation ? statisticsTextBox.Height + statisticsTextBox.Margin.Top + statisticsTextBox.Margin.Bottom : 0;
596      dataGridView.Size = new Size(Size.Width, Size.Height - offset - statisticsTextBoxHeight);
597    }
598
599   
600  }
601    #endregion
602}
Note: See TracBrowser for help on using the repository browser.