public void SetSortIcon(int columnIndex, SortOrder order)
        {
            IntPtr columnHeader = this.HeaderHandle;

            for (int columnNumber = 0; columnNumber <= this.Columns.Count - 1; columnNumber++)
            {
                // Get current listview column info
                var lvcol = new NativeMethods.LVCOLUMN(NativeMethods.ListViewColumMask.Fmt);
                NativeMethods.SendMessage(this.Handle, NativeMethods.ListViewMessage.GetColumn, columnNumber, lvcol);

                // Get current header info
                var hditem = new NativeMethods.HDITEM(NativeMethods.HeaderItemMask.Format | NativeMethods.HeaderItemMask.DISetItem);
                NativeMethods.SendMessage(columnHeader, NativeMethods.HeaderMessage.GetItem, columnNumber, hditem);

                // Update header with column info
                hditem.Format |= (NativeMethods.HeaderItemFormat)((uint)lvcol.Format & 0x1001803);
                if ((lvcol.Format & NativeMethods.ListViewColumnFormat.NoTitle) == 0)
                {
                    hditem.ShowText = true;
                }

                // Set header image info
                if (!(order == SortOrder.None) && columnNumber == columnIndex)
                {
                    hditem.ImageDisplay = (order == System.Windows.Forms.SortOrder.Descending) ? NativeMethods.HeaderItemImageDisplay.DownArrow : NativeMethods.HeaderItemImageDisplay.UpArrow;
                }
                else
                {
                    hditem.ImageDisplay = NativeMethods.HeaderItemImageDisplay.None;
                }

                // Update header
                NativeMethods.SendMessage(columnHeader, NativeMethods.HeaderMessage.SetItem, columnNumber, hditem);
            }
        }
Exemplo n.º 2
0
        public static void SetColumnDropDown(this ListView listView, int columnIndex, bool enable)
        {
            if (columnIndex < 0 || (columnIndex >= 0 && listView.Columns == null) || columnIndex >= listView.Columns.Count)
            {
                throw new ArgumentOutOfRangeException(nameof(columnIndex));
            }

            if (listView.IsHandleCreated)
            {
                var lvc = new NativeMethods.LVCOLUMN(NativeMethods.ListViewColumMask.Fmt);
                NativeMethods.SendMessage(listView.Handle, NativeMethods.ListViewMessage.GetColumn, columnIndex, lvc);
                if (enable)
                {
                    lvc.Format |= NativeMethods.ListViewColumnFormat.SplitButton;
                }
                else
                {
                    lvc.Format &= ~NativeMethods.ListViewColumnFormat.SplitButton;
                }
                NativeMethods.SendMessage(listView.Handle, NativeMethods.ListViewMessage.SetColumn, columnIndex, lvc);
                listView.InvalidateHeader();
            }
        }
Exemplo n.º 3
0
        /// <include file='doc\ListView.uex' path='docs/doc[@for="ListView.SetColumnInfo"]/*' />
        /// <devdoc>
        /// </devdoc>
        /// <internalonly/>
        internal void SetColumnInfo(int mask, ColumnHeader ch) {
            if (IsHandleCreated) {
                Debug.Assert((mask & ~(NativeMethods.LVCF_FMT | NativeMethods.LVCF_TEXT | NativeMethods.LVCF_IMAGE)) == 0, "Unsupported mask in setColumnInfo");
                NativeMethods.LVCOLUMN lvColumn = new NativeMethods.LVCOLUMN();
                lvColumn.mask  = mask;

                if ((mask & NativeMethods.LVCF_IMAGE) != 0 || (mask & NativeMethods.LVCF_FMT) != 0) {
                    // When we set the ImageIndex we also have to alter the column format.
                    // This means that we have to include the TextAlign into the column format.

                    lvColumn.mask |= NativeMethods.LVCF_FMT;

                    if (ch.ActualImageIndex_Internal > -1) {
                        // you would think that setting iImage would be enough.
                        // actually we also have to set the format to include LVCFMT_IMAGE
                        lvColumn.iImage = ch.ActualImageIndex_Internal;
                        lvColumn.fmt |= NativeMethods.LVCFMT_IMAGE;
                    }

                    lvColumn.fmt |= (int) ch.TextAlign;
                }

                if ((mask & NativeMethods.LVCF_TEXT) != 0) {
                    lvColumn.pszText    = Marshal.StringToHGlobalAuto(ch.Text);
                }

                int retval = (int)UnsafeNativeMethods.SendMessage(new HandleRef(this, Handle), NativeMethods.LVM_SETCOLUMN, ch.Index, lvColumn);
                if ((mask & NativeMethods.LVCF_TEXT) != 0) {
                    Marshal.FreeHGlobal(lvColumn.pszText);
                }

                if (0 == retval)
                    throw new InvalidOperationException(SR.GetString(SR.ListViewColumnInfoSet));
                // vsw 383220: when running on AMD64 the list view does not invalidate the column header.
                // So we do it ourselves.
                InvalidateColumnHeaders();
            }
        }
Exemplo n.º 4
0
 public static extern IntPtr SendMessage(HandleRef hWnd, int msg, int wParam, NativeMethods.LVCOLUMN lParam);