title: C# sort datagridview on column header click
body: <p>:)
  I have a datagridview and I fill it by List (I get data from 2 text files), but when I tried to click on a column header (I tried with all columns headers), I can't sort my datagridview data. This is my code:</p>
  
  <pre><code> public class Data1
      {
          public string Campionato { get; set; }
          public string Data { get; set; }
          public string Home { get; set; }
          public string Away { get; set; }
          public int HSFT { get; set; }
          public int ASFT { get; set; }
          public int HSHT { get; set; }
          public int ASHT { get; set; }
          public int HSSH { get; set; }
          public int ASSH { get; set; }
      }
  
      public class Data2 
      {
          public string Home { get; set; }
          public string Away { get; set; }
          public int HSFT { get; set; }
          public int ASFT { get; set; }
          public string HODD { get; set; }
          public string XODD { get; set; }
          public string AODD { get; set; } //no name in sample
          public string Data { get; set; }
          public string RisFin { get; set; } //no name in sample
          public string Over05SH { get; set; }
          public string Over05HT { get; set; }
          public string Over15HT { get; set; }
          public string Over05FT { get; set; }
          public string Over15FT { get; set; }
          public string Over25FT { get; set; }
          public string Over35FT { get; set; }
          public string Over45FT { get; set; }
  
  
  
      }
  
      public class CombinedData 
      {
          public string Campionato { get; set; }
          public string Data { get; set; }
          public string Home { get; set; }
          public string Away { get; set; }
          public int HSFT { get; set; }
          public int ASFT { get; set; }
          public int HSHT { get; set; }
          public int ASHT { get; set; }
          public int HSSH { get; set; }
          public int ASSH { get; set; }
          public string HODD { get; set; }
          public string XODD { get; set; }
          public string AODD { get; set; } //some name
          public string RisFin { get; set; } //no name in sample
          public string Over05SH { get; set; }
          public string Over05HT { get; set; }
          public string Over15HT { get; set; }
          public string Over05FT { get; set; }
          public string Over15FT { get; set; }
          public string Over25FT { get; set; }
          public string Over35FT { get; set; }
          public string Over45FT { get; set; }
  
      }
  </code></pre>
  
  <hr>
  
  <pre><code>var data1 = File.ReadAllLines("read" + campionatoselezTxt.Text + "stats.txt").ToList();
          var data2 = File.ReadAllLines("read" + campionatoselezTxt.Text + "bex.txt").ToList();
  
  
          var dataList1 = new List&lt;Data1&gt;();
          foreach (var data in data1)
          {
              var columns = data.Split(';'); 
              dataList1.Add(new Data1
              {
                  Campionato = columns[0],
                  Data = columns[1],
                  Home = columns[2],
                  Away = columns[3],
  
                  HSFT = int.Parse(columns[4]),
                  ASFT = int.Parse(columns[5]),
                  HSHT = int.Parse(columns[6]),
                  ASHT = int.Parse(columns[7]),
                  HSSH = int.Parse(columns[8]),
                  ASSH = int.Parse(columns[9])
                  //other int properties
              });
          }
  
          var dataList2 = new List&lt;Data2&gt;();
          foreach (var data in data2)
          {
              var columns = data.Split(';'); 
              dataList2.Add(new Data2
              {
                  Home = columns[0],
                  Away = columns[1],
                  HODD = columns[4],
                  XODD = columns[5],
                  AODD = columns[6],
  
  
              });
          }
  
          var combinedDataList = from d1 in dataList1 
                                 //join d2 in dataList2 on d1.Home equals d2.Home
                                 join d2 in dataList2 on new { d1.Home, d1.Away } equals new { d2.Home, d2.Away }
  
                                 select new CombinedData
                                 {
                                     Campionato = d1.Campionato,
                                     Data = d1.Data,
                                     Home = d2.Home,
                                     Away = d2.Away,
                                     HSFT = d1.HSFT,
                                     ASFT = d1.ASFT,
                                     HSHT = d1.HSHT,
                                     ASHT = d1.ASHT,
                                     HSSH = d1.HSSH,
                                     ASSH = d1.ASSH,
                                     HODD = d2.HODD,
                                     XODD = d2.XODD,
                                     AODD = d2.AODD,
                                     RisFin = d2.RisFin,
                                     Over05SH = d2.Over05SH
  
                                 }; //map all properties
  
          finabexDgv.DataSource = combinedDataList.ToList(); 
          finabexDgv.AllowUserToOrderColumns = true;   
  </code></pre>
  
  <p>I'd like to have a possibility to sort by clicking columns headers.</p>
  
  <p>I need your advices, please :)</p>
  
  <p>Happy Sunday!</p>