public string this[int columnIndex] { get { if (!this.owner.IsHandleCreated) { return(""); } NativeMethods.HDTEXTFILTER hdtextfilter = default(NativeMethods.HDTEXTFILTER); hdtextfilter.pszText = new string(new char[256 * Marshal.SystemDefaultCharSize]); hdtextfilter.cchTextMax = 256; IntPtr intPtr = Marshal.AllocHGlobal(Marshal.SizeOf(hdtextfilter)); string pszText; try { Marshal.StructureToPtr(hdtextfilter, intPtr, false); InternalNativeMethods.HDITEM hditem = default(InternalNativeMethods.HDITEM); hditem.mask = 256U; hditem.pvFilter = intPtr; InternalUnsafeNativeMethods.SendMessage(this.owner.HeaderHandle, NativeMethods.HDM_GETITEM, (IntPtr)columnIndex, ref hditem); pszText = ((NativeMethods.HDTEXTFILTER)Marshal.PtrToStructure(intPtr, typeof(NativeMethods.HDTEXTFILTER))).pszText; } finally { Marshal.FreeHGlobal(intPtr); } return(pszText); } set { NativeMethods.HDTEXTFILTER hdtextfilter = default(NativeMethods.HDTEXTFILTER); hdtextfilter.pszText = value; hdtextfilter.cchTextMax = value.Length + 1; IntPtr intPtr = Marshal.AllocHGlobal(Marshal.SizeOf(hdtextfilter)); try { Marshal.StructureToPtr(hdtextfilter, intPtr, false); InternalNativeMethods.HDITEM hditem = default(InternalNativeMethods.HDITEM); hditem.mask = 256U; hditem.type = 0U; hditem.pvFilter = intPtr; InternalUnsafeNativeMethods.SendMessage(this.owner.HeaderHandle, NativeMethods.HDM_SETITEM, (IntPtr)columnIndex, ref hditem); } finally { Marshal.FreeHGlobal(intPtr); } } }
public static extern IntPtr SendMessage(HandleRef hWnd, int msg, IntPtr wParam, [In][Out] ref InternalNativeMethods.HDITEM lparam);