title: how to sort the datagridview column Got an error : Argument NUll Exception Was Unhandled
body: <p>I am binding the data grid view  by using the following linq to entity framework query  by using the following code..</p>
  
  <pre><code>        private void EquipmentFinder_Load(object sender, EventArgs e)
      {
          SetupCategories();
          productgridview.RowTemplate.Height = 130;
          var products = from prods in axe.product1
                         select new
                         {
                             productid = prods.product_Id,   //0                            
                             productnam =  prods.product_Name, //1
                             productimage = prods.product_Image, //2
                             productprice = prods.product_Price,//3
                             productdescr = prods.product_Description, //4
  
                         };
  
          productbindingsource.DataSource = products;
          productgridview.DataSource = productbindingsource;          
          productgridview.Columns[0].Visible = false;
          productgridview.Columns[4].Visible = false;
      }  
  </code></pre>
  
  <p>I have got the columns product id , product image ,product name ,product desription,product price..</p>
  
  <p>i have made some of the columns are not visible for the purpose of client ..</p>
  
  <p>now i want to sort the columns by clicking on the column header ....</p>
  
  <p>Note: here the product.image is stored as byte of arrays in database ....</p>
  
  <p>i dont know how to compare the bytes and sorting like that....</p>
  
  <p>would any one pls help on this one......</p>
  
  <p>many thanks...</p>
  
  <p>MODIFIED CODE: </p>
  
  <pre><code>          private void productgridview_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
      {
         DataGridViewColumn newcolumn =  productgridview.Columns.GetColumnCount(DataGridViewElementStates.Selected) == 1 ? productgridview.SelectedColumns[0] : null;
         DataGridViewColumn oldColumn = productgridview.SortedColumn;
         ListSortDirection direction;
  
         if (oldColumn != null)
         {
             // Sort the same column again, reversing the SortOrder.
             if (oldColumn == newcolumn &amp;&amp;
                 productgridview.SortOrder == SortOrder.Ascending)
             {
                 direction = ListSortDirection.Descending;
             }
             else
             {
                 // Sort a new column and remove the old SortGlyph.
                 direction = ListSortDirection.Ascending;
                 oldColumn.HeaderCell.SortGlyphDirection = SortOrder.None;
             }
         }
         else
         {
             direction = ListSortDirection.Ascending;
         }
  
  
             productgridview.Sort(newcolumn, direction);
             newcolumn.HeaderCell.SortGlyphDirection =
                 direction == ListSortDirection.Ascending ?
                 SortOrder.Ascending : SortOrder.Descending;
  
  
  
      }
  </code></pre>
  
  <p>got An error:  Argument NUll Exception Was Unhandled ..</p>
  
  <pre><code>           Value cannot be null.
             Parameter name: dataGridViewColumn
  </code></pre>
  
  <p>would any one help on this....</p>