private void SetAllGroupState(ListViewGroupState state, bool on = true) { if (IsHandleCreated) { LVGROUP group = new LVGROUP(ListViewGroupMask.State); group.SetState(state, on); //group.Subtitle = "Dog"; for (int i = 0; i < Groups.Count; i++) { SendMessage(ListViewMessage.SetGroupInfo, i, group); } using (LVGROUP grp = new LVGROUP(ListViewGroupMask.Subtitle)) { int res = SendMessage(ListViewMessage.GetGroupInfoByIndex, 0, grp); if (res >= 0) { System.Diagnostics.Debug.WriteLine(grp.Subtitle); } } RecreateHandle(); } }
public void SetGroupCollapse(GroupState state) { IntPtr ptr = IntPtr.Zero; try { LVGROUP group = new LVGROUP(); int size = Marshal.SizeOf(group); ptr = Marshal.AllocHGlobal(size); for (int i = 0; i < this.Groups.Count; i++) { try { group.cbSize = size; group.state = (int)state; group.mask = LVGF_STATE; group.iGroupId = GetGroupID(this.Groups[i]); Marshal.StructureToPtr(group, ptr, false); SendMessage(this.Handle, LVM_SETGROUPINFO, group.iGroupId, ptr); } catch (Exception) { } } } catch (Exception) { } finally { if (ptr != IntPtr.Zero) { Marshal.FreeHGlobal(ptr); } } }
//mxd. Collapsible groups support. Created using http://www.codeproject.com/Articles/31276/Add-Group-Collapse-Behavior-on-a-Listview-Control as a reference public bool SetGroupCollapsed(ListViewGroup group, bool collapsed) { // Insanity checks... if (!this.Groups.Contains(group)) { return(false); } if (Environment.OSVersion.Version.Major < 6) { return(false); //Only Vista and forward allows collapse of ListViewGroups } if (this.InvokeRequired) { return((bool)this.Invoke(new CallBackSetGroupCollapsible(SetGroupCollapsed), group, collapsed)); } LVGROUP groupstruct = new LVGROUP(); groupstruct.cbSize = Marshal.SizeOf(typeof(LVGROUP)); groupstruct.state = (int)((collapsed ? GroupState.COLLAPSED : GroupState.EXPANDED) | GroupState.COLLAPSIBLE); groupstruct.stateMask = (int)(GroupState.COLLAPSIBLE | GroupState.COLLAPSED); groupstruct.mask = 4; // LVGF_STATE SendMessage(this.Handle, 0x1000 + 147, GetGroupID(group), ref groupstruct); // #define LVM_SETGROUPINFO (LVM_FIRST + 147) return(true); }
public static void SetGroupCollapse(GroupState state, ListView listview) { for (int i = 0; i <= listview.Groups.Count; i++) { LVGROUP group = new LVGROUP(); group.cbSize = Marshal.SizeOf(group); group.state = (int)state; // LVGS_COLLAPSIBLE group.mask = 4; // LVGF_STATE group.iGroupId = i; IntPtr ip = IntPtr.Zero; try { ip = Marshal.AllocHGlobal(group.cbSize); //Marshal.StructureToPtr(group, ip, true); Marshal.StructureToPtr(group, ip, false); SendMessage(listview.Handle, 0x1000 + 147, i, ip); // #define LVM_SETGROUPINFO (LVM_FIRST + 147) } catch (Exception ex) { System.Diagnostics.Trace.WriteLine (ex.Message + Environment.NewLine + ex.StackTrace); } finally { if (null != ip) { Marshal.FreeHGlobal(ip); } } } }
// sollte nach dem die gruppen hinzugefügt worden sind aufgerufen werden, jedoch am besten im form.shown event internal void MakeCollapsable() { if (Environment.OSVersion.Version.Major < 6) { return; } // Not supported by OS const int lvmFirst = 0x1000; const int LVM_SETGROUPINFO = (lvmFirst + 147); for (int i = 0; i <= Groups.Count - 1; i++) { var grp = new LVGROUP(); grp.CbSize = Marshal.SizeOf(grp); grp.State = ListViewGroupState.Collapsible; grp.Mask = ListViewGroupMask.State; grp.IGroupId = GetGroupID(Groups[i]); //If grp.IGroupId = -1 Then grp.IGroupId = i if (grp.IGroupId >= 0) { SendMessage(Handle, LVM_SETGROUPINFO, grp.IGroupId, ref grp); } } }
internal void SetGroupState(ListViewGroupEx group, ListViewGroupState item, bool value) { LVGROUP mgroup = new LVGROUP(ListViewGroupMask.State); mgroup.SetState(item, value); this.CallWhenHandleValid(c => SendMessage(ListViewMessage.SetGroupInfo, group.ID, mgroup)); }
public static int AddListViewGroup(XPListView lst, string text, int index) { LVGROUP apiGroup; int ptrRetVal; try { if (lst == null) { return(-1); } apiGroup = new LVGROUP(); apiGroup.mask = LVGF_GROUPID | LVGF_HEADER | LVGF_STATE; apiGroup.pszHeader = text; apiGroup.cchHeader = apiGroup.pszHeader.Length; apiGroup.iGroupId = index; apiGroup.stateMask = LVGS_NORMAL; apiGroup.state = LVGS_NORMAL; apiGroup.cbSize = Marshal.SizeOf(typeof(LVGROUP)); ptrRetVal = (int)SendMessage(lst.Handle, ListViewAPI.LVM_INSERTGROUP, -1, ref apiGroup); return(ptrRetVal); } catch (Exception ex) { throw new System.Exception("An exception in ListViewAPI.AddListViewGroup occured: " + ex.Message); } }
private static void setGrpFooter(ListViewGroup lstvwgrp, string footer) { if (Environment.OSVersion.Version.Major < 6) //Only Vista and forward allows footer on ListViewGroups { return; } if (lstvwgrp == null || lstvwgrp.ListView == null) { return; } if (lstvwgrp.ListView.InvokeRequired) { lstvwgrp.ListView.Invoke(new CallbackSetGroupString(setGrpFooter), lstvwgrp, footer); } else { int? GrpId = GetGroupID(lstvwgrp); int gIndex = lstvwgrp.ListView.Groups.IndexOf(lstvwgrp); LVGROUP group = new LVGROUP(); group.CbSize = Marshal.SizeOf(group); group.PszFooter = footer; group.Mask = ListViewGroupMask.Footer; if (GrpId != null) { group.IGroupId = GrpId.Value; SendMessage(lstvwgrp.ListView.Handle, LVM_SETGROUPINFO, GrpId.Value, ref group); } else { group.IGroupId = gIndex; SendMessage(lstvwgrp.ListView.Handle, LVM_SETGROUPINFO, gIndex, ref group); } } }
public static int AddListViewGroup(IntPtr listHandle, string text, int index) { LVGROUP apiGroup; IntPtr ptrRetVal; try { if (listHandle == IntPtr.Zero) { return(-1); } if (text == null) { text = String.Empty; } apiGroup = new LVGROUP(); apiGroup.mask = LVGF_GROUPID | LVGF_HEADER | LVGF_STATE; apiGroup.pszHeader = Marshal.StringToCoTaskMemUni(text); apiGroup.cchHeader = text.Length; apiGroup.iGroupId = index; apiGroup.stateMask = LVGS_NORMAL; apiGroup.state = LVGS_NORMAL; apiGroup.cbSize = Marshal.SizeOf(typeof(LVGROUP)); ptrRetVal = SendMessage(listHandle, W32_LVM.LVM_INSERTGROUP, -1, ref apiGroup); return(ptrRetVal.ToInt32()); } catch (Exception ex) { throw new Exception("An exception in API.AddListViewGroup occured: " + ex.Message); } }
public void SetGroupState(ListViewGroup lvGroup, GroupState state) { IntPtr ptr = IntPtr.Zero; try { LVGROUP group = new LVGROUP(); int size = Marshal.SizeOf(group); ptr = Marshal.AllocHGlobal(size); group.cbSize = size; group.state = (int)state; group.mask = LVGF_STATE; group.iGroupId = GetGroupID(lvGroup); Marshal.StructureToPtr(group, ptr, false); SendMessage(this.Handle, LVM_SETGROUPINFO, group.iGroupId, ptr); } catch (Exception) { } finally { if (ptr != IntPtr.Zero) { Marshal.FreeHGlobal(ptr); } } }
protected override void WndProc(ref Message m) { switch (m.Msg) { case 0x1000 + 145: // LVM_INSERTGROUP = LVM_FIRST + 145; // Add the collapsible feature id needed LVGROUP lvgroup = (LVGROUP)Marshal.PtrToStructure(m.LParam, typeof(LVGROUP)); lvgroup.state = (int)GroupState.COLLAPSIBLE; // LVGS_COLLAPSIBLE lvgroup.mask = lvgroup.mask ^ 4; // LVGF_STATE Marshal.StructureToPtr(lvgroup, m.LParam, true); base.WndProc(ref m); break; case 0x202: //WM_LBUTTONUP base.DefWndProc(ref m); base.WndProc(ref m); break; /*case 0x83: // WM_NCCALCSIZE * int style = (int)GetWindowLong(this.Handle, GwlStyle); * if ((style & WsHscroll) == WsHscroll) * SetWindowLong(this.Handle, GwlStyle, style & ~WsHscroll); * base.WndProc(ref m); * break;*/ default: base.WndProc(ref m); break; } }
/// <summary>Sets the footer text and alignment for a list view group.</summary> /// <param name="group">The group.</param> /// <param name="footer">The footer text.</param> /// <param name="footerAlignment">The footer alignment.</param> public static void SetFooter(this ListViewGroup group, string footer = null, HorizontalAlignment footerAlignment = HorizontalAlignment.Left) { var groupId = GetGroupId(group); if (groupId >= 0) { using var lvgroup = new LVGROUP { Footer = footer, Alignment = MakeAlignment(group.HeaderAlignment, footerAlignment) }; SendMessage(group.ListView.Handle, ListViewMessage.LVM_SETGROUPINFO, groupId, lvgroup); } }
public static void SetTask(this ListViewGroup group, string taskLink) { var groupId = GetGroupId(group); if (groupId >= 0) { using var lvgroup = new LVGROUP { TaskLink = taskLink }; SendMessage(group.ListView.Handle, ListViewMessage.LVM_SETGROUPINFO, groupId, lvgroup); } }
internal void UpdateGroupNative(ListViewGroupEx group, bool invalidate = true) { LVGROUP nGroup = group.AsLVGROUP(); nGroup.SetState(ListViewGroupState.Collapsible, collapsible); this.CallWhenHandleValid(c => { SendMessage(ListViewMessage.SetGroupInfo, group.ID, nGroup); if (invalidate) { base.Invalidate(); } }); }
internal LVGROUP AsLVGROUP() { LVGROUP lvGrp = new LVGROUP(ListViewGroupMask.None, Header); if (ID != 0) { lvGrp.ID = ID; } if (HeaderAlignment != HorizontalAlignment.Left) { lvGrp.HeaderAlignment = HeaderAlignment; } if (FooterAlignment != HorizontalAlignment.Left) { lvGrp.FooterAlignment = FooterAlignment; } if (Footer != null) { lvGrp.Footer = Footer; } if (DescriptionBottom != null) { lvGrp.DescriptionBottom = DescriptionBottom; } if (DescriptionTop != null) { lvGrp.DescriptionTop = DescriptionTop; } if (Subtitle != null) { lvGrp.Subtitle = Subtitle; } if (Task != null) { lvGrp.Task = Task; } if (TitleImageIndexer.ActualIndex > -1) { lvGrp.TitleImageIndex = TitleImageIndexer.ActualIndex; } if (ExtendedImageIndexer.ActualIndex > -1) { lvGrp.ExtendedImageIndex = ExtendedImageIndexer.ActualIndex; } ListViewGroupState s, m; GetSetState(out m, out s); if (s != ListViewGroupState.Normal) { lvGrp.SetState(s); } return(lvGrp); }
private static void SetState(ListViewGroup group, ListViewGroupState state, bool value) { var groupId = GetGroupId(group); if (groupId >= 0) { var lvgroup = new LVGROUP(ListViewGroupMask.LVGF_STATE); { lvgroup.SetState(state, value); SendMessage(group.ListView.Handle, ListViewMessage.LVM_SETGROUPINFO, groupId, lvgroup); } } }
internal LVGROUP GetGroupInfo(int groupIndex, ListViewGroupMask mask) { if (IsHandleCreated) { try { LVGROUP mgroup = new LVGROUP(mask); if (0 != SendMessage(ListViewMessage.GetGroupInfoByIndex, groupIndex, mgroup)) { return(mgroup); } } catch { } } return(null); }
internal int GetGroupId(int groupIndex) { if (IsHandleCreated) { try { LVGROUP mgroup = new LVGROUP(ListViewGroupMask.GroupId); if (0 != SendMessage(ListViewMessage.GetGroupInfoByIndex, groupIndex, mgroup)) { return(mgroup.ID); } } catch { } } return(-1); }
public static void SetImage(this ListViewGroup group, int titleImageIndex, string descriptionTop = null, string descriptionBottom = null) { var groupId = GetGroupId(group); if (groupId >= 0) { using var lvgroup = new LVGROUP { TitleImageIndex = titleImageIndex }; if (descriptionBottom != null) { lvgroup.DescriptionBottom = descriptionBottom; } if (descriptionTop != null) { lvgroup.DescriptionTop = descriptionTop; } SendMessage(group.ListView.Handle, ListViewMessage.LVM_SETGROUPINFO, groupId, lvgroup); } }
// sollte nach dem die gruppen hinzugefügt worden sind aufgerufen werden, jedoch am besten im form.shown event internal void MakeCollapsable() { if (Environment.OSVersion.Version.Major < 6) return; // Not supported by OS const int lvmFirst = 0x1000; const int LVM_SETGROUPINFO = (lvmFirst + 147); for (int i = 0; i <= Groups.Count - 1; i++) { var grp = new LVGROUP(); grp.CbSize = Marshal.SizeOf(grp); grp.State = ListViewGroupState.Collapsible; grp.Mask = ListViewGroupMask.State; grp.IGroupId = GetGroupID(Groups[i]); //If grp.IGroupId = -1 Then grp.IGroupId = i if (grp.IGroupId >= 0) { SendMessage(Handle, LVM_SETGROUPINFO, grp.IGroupId, ref grp); } } }
private static int SetListViewGroupStyle(IntPtr listViewHandle, int groupID, ListViewGroupStyle style) { IntPtr LParam = IntPtr.Zero; int ReturnValue = -1; try { LVGROUP ListViewGroupParam; IntPtr Result; // Build the LVGROUP and marhsal to a pointer ListViewGroupParam = new LVGROUP() { cbSize = (uint)Marshal.SizeOf(typeof(LVGROUP)), state = style, mask = ListViewGroupFlags.STATE, iGroupId = groupID }; LParam = Marshal.AllocHGlobal((int)ListViewGroupParam.cbSize); Marshal.StructureToPtr(ListViewGroupParam, LParam, false); // Send the message to the ListView Result = NativeMethods.SendMessage(listViewHandle, ListViewMessage.LVM_SETGROUPINFO, new UIntPtr((uint)groupID), LParam); ReturnValue = Result.ToInt32(); } catch (Exception) { } finally { // Clean up if (LParam != null && LParam != IntPtr.Zero) { Marshal.FreeHGlobal(LParam); } } return(ReturnValue); }
private static void setGrpState(ListViewGroup lstvwgrp, ListViewGroupState state) { if (Environment.OSVersion.Version.Major < 6) //Only Vista and forward allows collaps of ListViewGroups { return; } if (lstvwgrp == null || lstvwgrp.ListView == null) { return; } if (lstvwgrp.ListView.InvokeRequired) { lstvwgrp.ListView.Invoke(new CallBackSetGroupState(setGrpState), lstvwgrp, state); } else { int? GrpId = GetGroupID(lstvwgrp); int gIndex = lstvwgrp.ListView.Groups.IndexOf(lstvwgrp); LVGROUP group = new LVGROUP(); group.CbSize = Marshal.SizeOf(group); group.State = state; group.Mask = ListViewGroupMask.State; if (GrpId != null) { group.IGroupId = GrpId.Value; SendMessage(lstvwgrp.ListView.Handle, LVM_SETGROUPINFO, GrpId.Value, ref group); SendMessage(lstvwgrp.ListView.Handle, LVM_SETGROUPINFO, GrpId.Value, ref group); } else { group.IGroupId = gIndex; SendMessage(lstvwgrp.ListView.Handle, LVM_SETGROUPINFO, gIndex, ref group); SendMessage(lstvwgrp.ListView.Handle, LVM_SETGROUPINFO, gIndex, ref group); } lstvwgrp.ListView.Refresh(); } }
public static extern IntPtr SendMessage(IntPtr hWnd, int msg, int wParam, ref LVGROUP lParam);
private void MakeGroupCollapsible(int State) { for (int i = 0; i <= listView1.Groups.Count ; i++ ) { LVGROUP group = new LVGROUP(); group.cbSize = Marshal.SizeOf(group); group.state = State; group.mask = 4; group.iGroupId = i; IntPtr ip = IntPtr.Zero; try { ip = Marshal.AllocHGlobal(Marshal.SizeOf(group)); Marshal.StructureToPtr(group, ip, false); SendMessage(listView1.Handle, 0x1000 + 147, (IntPtr)i, ip); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { if (ip != null) Marshal.FreeHGlobal(ip); } } }
IntPtr SendMessage(IntPtr hWnd, W32_LVM msg, int wParam, ref LVGROUP lParam);
public static extern int SendMessage(HandleRef hWnd, int msg, IntPtr wParam, ref LVGROUP lParam);
public static int AddListViewGroup(XPListView lst, string text, int index) { LVGROUP apiGroup; int ptrRetVal; try { if (lst == null) { return -1; } apiGroup = new LVGROUP(); apiGroup.mask = LVGF_GROUPID | LVGF_HEADER | LVGF_STATE; apiGroup.pszHeader = text; apiGroup.cchHeader = apiGroup.pszHeader.Length; apiGroup.iGroupId = index; apiGroup.stateMask = LVGS_NORMAL; apiGroup.state = LVGS_NORMAL; apiGroup.cbSize = Marshal.SizeOf(typeof (LVGROUP)); ptrRetVal = (int)SendMessage(lst.Handle, ListViewAPI.LVM_INSERTGROUP, -1, ref apiGroup); return ptrRetVal; } catch (Exception ex) { throw new System.Exception("An exception in ListViewAPI.AddListViewGroup occured: " + ex.Message); } }
private static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, ref LVGROUP lParam);
private int SendMessage(ListViewMessage msg, int wParam, LVGROUP group) => User32.SendMessage(Handle, msg, wParam, group).ToInt32();
public static extern IntPtr SendMessage(HandleRef hWnd, int msg, IntPtr wParam, ref LVGROUP lParam);
private static extern int SendMessage(IntPtr window, int message, int wParam, ref LVGROUP lParam);