Index: /trunk/sources/HeuristicLab.Data.Views/3.3/StringConvertibleMatrixView.Designer.cs
===================================================================
--- /trunk/sources/HeuristicLab.Data.Views/3.3/StringConvertibleMatrixView.Designer.cs	(revision 3313)
+++ /trunk/sources/HeuristicLab.Data.Views/3.3/StringConvertibleMatrixView.Designer.cs	(revision 3314)
@@ -94,4 +94,5 @@
       this.dataGridView.VirtualMode = true;
       this.dataGridView.Scroll += new System.Windows.Forms.ScrollEventHandler(this.dataGridView_Scroll);
+      this.dataGridView.ColumnHeaderMouseClick += new System.Windows.Forms.DataGridViewCellMouseEventHandler(this.dataGridView_ColumnHeaderMouseClick);
       this.dataGridView.CellValueNeeded += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.dataGridView_CellValueNeeded);
       this.dataGridView.CellParsing += new System.Windows.Forms.DataGridViewCellParsingEventHandler(this.dataGridView_CellParsing);
Index: /trunk/sources/HeuristicLab.Data.Views/3.3/StringConvertibleMatrixView.cs
===================================================================
--- /trunk/sources/HeuristicLab.Data.Views/3.3/StringConvertibleMatrixView.cs	(revision 3313)
+++ /trunk/sources/HeuristicLab.Data.Views/3.3/StringConvertibleMatrixView.cs	(revision 3314)
@@ -22,4 +22,5 @@
 using System;
 using System.ComponentModel;
+using System.Collections.Generic;
 using System.Drawing;
 using System.Linq;
@@ -38,4 +39,8 @@
     }
 
+    private int[] virtualRowIndizes;
+    private List<KeyValuePair<int, SortOrder>> sortedColumnIndizes;
+    RowComparer rowComparer;
+
     public StringConvertibleMatrixView() {
       InitializeComponent();
@@ -45,4 +50,6 @@
       errorProvider.SetIconAlignment(columnsTextBox, ErrorIconAlignment.MiddleLeft);
       errorProvider.SetIconPadding(columnsTextBox, 2);
+      sortedColumnIndizes = new List<KeyValuePair<int, SortOrder>>();
+      rowComparer = new RowComparer();
     }
     public StringConvertibleMatrixView(IStringConvertibleMatrix content)
@@ -66,4 +73,6 @@
     protected override void OnContentChanged() {
       base.OnContentChanged();
+      sortedColumnIndizes.Clear();
+      virtualRowIndizes = new int[0];
       if (Content == null) {
         Caption = "StringConvertibleMatrix View";
@@ -89,4 +98,5 @@
       dataGridView.ColumnCount = 0;
       if ((Content.Rows > 0) && (Content.Columns > 0)) {
+        virtualRowIndizes = Enumerable.Range(0, Content.Rows - 1).ToArray();
         dataGridView.RowCount = Content.Rows;
         dataGridView.ColumnCount = Content.Columns;
@@ -111,5 +121,5 @@
         if (Content.RowNames.Count() != 0)
           dataGridView.Rows[i].HeaderCell.Value = Content.RowNames.ElementAt(i);
-        else 
+        else
           dataGridView.Rows[i].HeaderCell.Value = i.ToString();
       }
@@ -121,7 +131,5 @@
         Invoke(new EventHandler<EventArgs<int, int>>(Content_ItemChanged), sender, e);
       else {
-        dataGridView.Rows[e.Value].Cells[e.Value2].Value = Content.GetValue(e.Value, e.Value2);
-        Size size = dataGridView.Rows[e.Value].Cells[e.Value2].PreferredSize;
-        dataGridView.Columns[e.Value2].Width = Math.Max(dataGridView.Columns[e.Value2].Width, size.Width);
+        dataGridView.InvalidateCell(e.Value, e.Value2);
       }
     }
@@ -186,6 +194,7 @@
     private void dataGridView_CellParsing(object sender, DataGridViewCellParsingEventArgs e) {
       string value = e.Value.ToString();
-      e.ParsingApplied = Content.SetValue(value, e.RowIndex, e.ColumnIndex);
-      if (e.ParsingApplied) e.Value = Content.GetValue(e.RowIndex, e.ColumnIndex);
+      int rowIndex = virtualRowIndizes[e.RowIndex];
+      e.ParsingApplied = Content.SetValue(value, rowIndex, e.ColumnIndex);
+      if (e.ParsingApplied) e.Value = Content.GetValue(rowIndex, e.ColumnIndex);
     }
     private void dataGridView_CellEndEdit(object sender, DataGridViewCellEventArgs e) {
@@ -193,5 +202,8 @@
     }
     private void dataGridView_CellValueNeeded(object sender, DataGridViewCellValueEventArgs e) {
-      e.Value = Content.GetValue(e.RowIndex, e.ColumnIndex);
+      if (e.RowIndex < virtualRowIndizes.Length) {
+        int rowIndex = virtualRowIndizes[e.RowIndex];
+        e.Value = Content.GetValue(rowIndex, e.ColumnIndex);
+      }
     }
 
@@ -203,7 +215,82 @@
       UpdateRowHeaders();
     }
+
+    private void dataGridView_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e) {
+      //if (Content != null && Content.SortableView) {
+      if (e.Button == MouseButtons.Left) {
+        bool addToSortedIndizes = (Control.ModifierKeys & Keys.Control) == Keys.Control;
+        SortOrder newSortOrder = SortOrder.Ascending;
+        if (sortedColumnIndizes.Any(x => x.Key == e.ColumnIndex)) {
+          SortOrder oldSortOrder = sortedColumnIndizes.Where(x => x.Key == e.ColumnIndex).First().Value;
+          int enumLength = Enum.GetValues(typeof(SortOrder)).Length;
+          newSortOrder = oldSortOrder = (SortOrder)Enum.Parse(typeof(SortOrder), ((((int)oldSortOrder) + 1) % enumLength).ToString());
+        }
+
+        if (!addToSortedIndizes)
+          sortedColumnIndizes.Clear();
+
+        if (sortedColumnIndizes.Any(x => x.Key == e.ColumnIndex)) {
+          int sortedIndex = sortedColumnIndizes.FindIndex(x => x.Key == e.ColumnIndex);
+          if (newSortOrder != SortOrder.None)
+            sortedColumnIndizes[sortedIndex] = new KeyValuePair<int, SortOrder>(e.ColumnIndex, newSortOrder);
+          else
+            sortedColumnIndizes.RemoveAt(sortedIndex);
+        } else
+          if (newSortOrder != SortOrder.None)
+            sortedColumnIndizes.Add(new KeyValuePair<int, SortOrder>(e.ColumnIndex, newSortOrder));
+        Sort();
+      }
+      //}
+    }
+
+    private void Sort() {
+      int[] newSortedIndex = Enumerable.Range(0, Content.Rows - 1).ToArray();
+      if (sortedColumnIndizes.Count != 0) {
+        rowComparer.sortedIndizes = sortedColumnIndizes;
+        rowComparer.matrix = Content;
+        Array.Sort(newSortedIndex, rowComparer);
+      }
+      virtualRowIndizes = newSortedIndex;
+      dataGridView.Invalidate();
+      foreach (DataGridViewColumn col in this.dataGridView.Columns)
+        col.HeaderCell.SortGlyphDirection = SortOrder.None;
+      foreach (KeyValuePair<int, SortOrder> p in sortedColumnIndizes)
+        this.dataGridView.Columns[p.Key].HeaderCell.SortGlyphDirection = p.Value;
+    }
     #endregion
 
-
+    private class RowComparer : IComparer<int> {
+      public List<KeyValuePair<int, SortOrder>> sortedIndizes;
+      public IStringConvertibleMatrix matrix;
+      public RowComparer() {
+      }
+
+      public int Compare(int x, int y) {
+        int result = 0;
+        double double1, double2;
+        DateTime dateTime1, dateTime2;
+        string string1, string2;
+
+        foreach (KeyValuePair<int, SortOrder> pair in sortedIndizes) {
+          string1 = matrix.GetValue(x, pair.Key);
+          string2 = matrix.GetValue(y, pair.Key);
+          if (double.TryParse(string1, out double1) && double.TryParse(string2, out double2))
+            result = double1.CompareTo(double2);
+          else if (DateTime.TryParse(string1, out dateTime1) && DateTime.TryParse(string2, out dateTime2))
+            result = dateTime1.CompareTo(dateTime2);
+          else {
+            if (string1 != null)
+              result = string1.CompareTo(string2);
+            else if (string2 != null)
+              result = string2.CompareTo(string1) * -1;
+          }
+          if (pair.Value == SortOrder.Descending)
+            result *= -1;
+          if (result != 0)
+            return result;
+        }
+        return result;
+      }
+    }
   }
 }
