/// <summary>
 ///     Change the width of the given column. This is a helper function to
 ///     facilitate the final step in updating the header. SetItemWidth does
 ///     not update the data in the tree control's VirtualTreeColumnHeader
 ///     structures.
 /// </summary>
 /// <param name="index">The display column</param>
 /// <param name="itemWidth">The new width for the column</param>
 public void SetItemWidth(int index, int itemWidth)
 {
     // The header items can get out of sync here with drag/drop reordering. The
     // index requested here will always be the displayed order, not the true index,
     // so we need to switch to the true index before moving on.
     index = OrderToIndex(index);
     var item = new NativeMethods.HDITEM();
     item.cxy = itemWidth;
     item.mask = NativeMethods.HDITEM.Mask.HDI_WIDTH;
     NativeMethods.SendMessage(Handle, NativeMethods.HDM_SETITEMW, index, ref item);
 }
 /// <summary>
 ///     Add an item to the control. Always adds in the last position.
 /// </summary>
 /// <param name="columnHeader">The header information</param>
 /// <param name="itemWidth"></param>
 public void AddItem(VirtualTreeColumnHeader columnHeader, int itemWidth)
 {
     var item = new NativeMethods.HDITEM();
     item.cxy = itemWidth;
     item.mask = NativeMethods.HDITEM.Mask.HDI_WIDTH;
     SetAppearanceFields(ref columnHeader, ref item);
     NativeMethods.SendMessage(Handle, NativeMethods.HDM_INSERTITEMW, int.MaxValue, ref item);
 }
 /// <summary>
 ///     Update the appearance fields (string, glyph, and style) to the new header settings. This
 ///     cannot be used to update the width or position of the header.
 /// </summary>
 /// <param name="columnHeader">The header with the current settings</param>
 /// <param name="displayColumn">The display column to update</param>
 public void UpdateItemAppearance(VirtualTreeColumnHeader columnHeader, int displayColumn)
 {
     if (IsHandleCreated)
     {
         var item = new NativeMethods.HDITEM();
         SetAppearanceFields(ref columnHeader, ref item);
         if (item.mask != 0)
         {
             NativeMethods.SendMessage(Handle, NativeMethods.HDM_SETITEMW, OrderToIndex(displayColumn), ref item);
         }
     }
 }
 /// <summary>
 ///     Get the current display column for a header index, such as the header
 ///     index sent with the NMHEADER structure to HDN_* notification messages.
 /// </summary>
 /// <param name="index">The header index</param>
 /// <returns>The column the header is currently displayed at.</returns>
 protected int IndexToOrder(int index)
 {
     if (IsHandleCreated)
     {
         var item = new NativeMethods.HDITEM();
         item.iOrder = index;
         item.mask = NativeMethods.HDITEM.Mask.HDI_ORDER;
         NativeMethods.SendMessage(Handle, NativeMethods.HDM_GETITEMW, index, ref item);
         return item.iOrder;
     }
     return index;
 }