示例#1
0
		public static extern IntPtr SendMessage(IntPtr hWnd, MSG Msg, int wParam, ref HDITEM lParam);
示例#2
0
    /// <summary>
    /// This is only to be used in SetSortCollumn(...)
    /// </summary>
    /// <param name="columnIndex"></param>
    /// <param name="order"></param>
    private void SetSortIcon(Int32 columnIndex, SortOrder order) {
      IntPtr columnHeader = User32.SendMessage(this.LVHandle, MSG.LVM_GETHEADER, 0, 0);
      for (Int32 columnNumber = 0; columnNumber <= this.Collumns.Count - 1; columnNumber++) {
        var item = new HDITEM { mask = HDITEM.Mask.Format };

        if (User32.SendMessage(columnHeader, MSG.HDM_GETITEM, columnNumber, ref item) == IntPtr.Zero) {
          throw new Win32Exception();
        }

        if (order != SortOrder.None && columnNumber == columnIndex) {
          switch (order) {
            case SortOrder.Ascending:
              item.fmt &= ~HDITEM.Format.SortDown;
              item.fmt |= HDITEM.Format.SortUp;
              break;

            case SortOrder.Descending:
              item.fmt &= ~HDITEM.Format.SortUp;
              item.fmt |= HDITEM.Format.SortDown;
              break;
          }
        } else {
          item.fmt &= ~HDITEM.Format.SortDown & ~HDITEM.Format.SortUp;
        }

        if (User32.SendMessage(columnHeader, MSG.HDM_SETITEM, columnNumber, ref item) == IntPtr.Zero) {
          throw new Win32Exception();
        }
      }
    }