public void SortViewByColumn(int index)
        {
            try
            {
                //handle of the "defView" --> container of the listView
                IntPtr hWndWin = NativeMethods.FindWindowEx(_dlgWrapper.Handle, IntPtr.Zero, "SHELLDLL_DefView", "");

                if (hWndWin != IntPtr.Zero)
                {
                    //change to details view
                    NativeMethods.SendMessage(new HandleRef(this, hWndWin), (int)Msg.WM_COMMAND, (IntPtr)(int)DefaultViewType.Details, IntPtr.Zero);

                    #region  sort by date
                    int HDN_FIRST      = (-300);
                    int HDN_ITEMCLICKW = (HDN_FIRST - 22);

                    //get the ListView//s hWnd
                    IntPtr hWndLV = NativeMethods.FindWindowEx(hWndWin, IntPtr.Zero, "SysListView32", IntPtr.Zero);
                    //get the ColumnHeaders hWnd
                    IntPtr hWndColHd = NativeMethods.FindWindowEx(hWndLV, IntPtr.Zero, "SysHeader32", IntPtr.Zero);

                    //now click on column 3 to sort for date
                    NMHEADER NMH = new NMHEADER();
                    NMH.hdr.hwndFrom = hWndColHd;
                    NMH.hdr.code     = (uint)HDN_ITEMCLICKW;
                    NMH.iItem        = index;
                    NMH.iButton      = 0;

                    // Initialize unmanged memory to hold the struct.
                    IntPtr ptrNMH = Marshal.AllocHGlobal(Marshal.SizeOf(NMH));
                    try
                    {
                        // Copy the struct to unmanaged memory.
                        Marshal.StructureToPtr(NMH, ptrNMH, false);

                        NativeMethods.SendMessage(new HandleRef(this, hWndLV), (uint)Msg.WM_NOTIFY, IntPtr.Zero, ptrNMH);
                        //click again for descending order = newest files first
                        NativeMethods.SendMessage(new HandleRef(this, hWndLV), (uint)Msg.WM_NOTIFY, IntPtr.Zero, ptrNMH);
                    }
                    finally
                    {
                        // Free the unmanaged memory.
                        Marshal.FreeHGlobal(ptrNMH);
                    }



                    ////if wanted give the dialog a larger size here
                    //If DialogXSize > 0 And DialogYSize > 0 Then
                    //   SetWindowPos hWndDlg, 0&, 0&, 0&, DialogXSize, DialogYSize, 0&
                    //End If
                    //}
                    #endregion
                }
            }
            catch
            {
            }
        }
    public void SortViewByColumn(int index)
    {
      try
      {
        //handle of the "defView" --> container of the listView
        IntPtr hWndWin = NativeMethods.FindWindowEx(_dlgWrapper.Handle, IntPtr.Zero, "SHELLDLL_DefView", "");

        if (hWndWin != IntPtr.Zero)
        {
          //change to details view
          NativeMethods.SendMessage(new HandleRef(this, hWndWin), (int)Msg.WM_COMMAND, (IntPtr)(int)DefaultViewType.Details, IntPtr.Zero);

          #region  sort by date
          int HDN_FIRST = (-300);
          int HDN_ITEMCLICKW = (HDN_FIRST - 22);

          //get the ListView//s hWnd
          IntPtr hWndLV = NativeMethods.FindWindowEx(hWndWin, IntPtr.Zero, "SysListView32", IntPtr.Zero);
          //get the ColumnHeaders hWnd
          IntPtr hWndColHd = NativeMethods.FindWindowEx(hWndLV, IntPtr.Zero, "SysHeader32", IntPtr.Zero);

          //now click on column 3 to sort for date
          NMHEADER NMH = new NMHEADER();
          NMH.hdr.hwndFrom = hWndColHd;
          NMH.hdr.code = (uint)HDN_ITEMCLICKW;
          NMH.iItem = index;
          NMH.iButton = 0;

          // Initialize unmanged memory to hold the struct.
          IntPtr ptrNMH = Marshal.AllocHGlobal(Marshal.SizeOf(NMH));
          try
          {

            // Copy the struct to unmanaged memory.
            Marshal.StructureToPtr(NMH, ptrNMH, false);

            NativeMethods.SendMessage(new HandleRef(this, hWndLV), (uint)Msg.WM_NOTIFY, IntPtr.Zero, ptrNMH);
            //click again for descending order = newest files first
            NativeMethods.SendMessage(new HandleRef(this, hWndLV), (uint)Msg.WM_NOTIFY, IntPtr.Zero, ptrNMH);
          }
          finally
          {
            // Free the unmanaged memory.
            Marshal.FreeHGlobal(ptrNMH);
          }



          ////if wanted give the dialog a larger size here
          //If DialogXSize > 0 And DialogYSize > 0 Then
          //   SetWindowPos hWndDlg, 0&, 0&, 0&, DialogXSize, DialogYSize, 0&
          //End If
          //}
          #endregion
        }
      }
      catch
      {
      }
    }