Sorting a List<> using linq in C#
<p>I would like to do "sorting"  under Datagridview ColumnHeaderMouseClick. 
Accending or Decending should need to be automatic, selected column value automatic. </p>

<p>I gone through many websites and tried some options but I could not be able to achieve my goal. </p>

<pre><code>private void lst_Install_Item_Main_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
    try
    {
        DataGridViewColumn newColumn = lst_Install_Item_Main.Columns[e.ColumnIndex];
        List&lt;test&gt; temp = (List&lt;test&gt;)lst_Install_Item_Main.DataSource;

        //var newList = temp.OrderBy(m =&gt; m.feet).ToList();
        //var newList = temp.AsQueryable().OrderBy(m =&gt; m.feet).ToList();
        temp.Sort((m1, m2) =&gt; m1.feet.CompareTo(m2.feet));

        lst_Install_Item_Main.DataSource = temp;
        lst_Install_Item_Main.Refresh();
    }
    catch (Exception ex)
    {
        MessageBox.Show("There was an error bringing sorting \n" + ex.Message, "Testing", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
}
</code></pre>

<p>Above code "sorting" the list on "feet" column but</p>

<ol>
<li>I would like to pass the columnname which user clicked, is that possible ?</li>
</ol>

<p>I have input like (1', 21', 123', 5', 10')
Above code sorting the list like >> (1', 10', 123', 21', 5')</p>

<ol start="2">
<li><p>But I want output like >> (1', 5', 10', 21', 123') 
Is that possible to achieve ?</p></li>
<li><p>How to achieve Ascending  or Descending here 
(I mean while I clicked first time it will do Ascending and while click on same column second time it should need to do Descending) </p></li>
</ol>

<p>Your suggestionshelp are greatly appreciated.  </p>