Exemplo n.º 1
0
        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();
            }
        }
Exemplo n.º 2
0
        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);
                }
            }
        }
Exemplo n.º 3
0
        //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);
        }
Exemplo n.º 4
0
 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);
             }
         }
     }
 }
Exemplo n.º 5
0
        // 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);
                }
            }
        }
Exemplo n.º 6
0
        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));
        }
Exemplo n.º 7
0
        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);
            }
        }
Exemplo n.º 8
0
 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);
         }
     }
 }
Exemplo n.º 9
0
            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);
                }
            }
Exemplo n.º 10
0
        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);
                }
            }
        }
Exemplo n.º 11
0
        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;
            }
        }
Exemplo n.º 12
0
        /// <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);
            }
        }
Exemplo n.º 13
0
        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);
            }
        }
Exemplo n.º 14
0
        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();
                                            }
                                     });
        }
Exemplo n.º 15
0
        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);
        }
Exemplo n.º 16
0
        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);
                }
            }
        }
Exemplo n.º 17
0
 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);
 }
Exemplo n.º 18
0
 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);
 }
Exemplo n.º 19
0
        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);
            }
        }
Exemplo n.º 20
0
		// 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);
				}
			}
		}
Exemplo n.º 21
0
        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);
        }
Exemplo n.º 22
0
 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();
     }
 }
Exemplo n.º 23
0
 public static extern IntPtr SendMessage(IntPtr hWnd, int msg, int wParam, ref LVGROUP lParam);
Exemplo n.º 24
0
        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);
                }

            }
        }
Exemplo n.º 25
0
 IntPtr SendMessage(IntPtr hWnd, W32_LVM msg, int wParam, ref LVGROUP lParam);
Exemplo n.º 26
0
 public static extern int SendMessage(HandleRef hWnd,
                                        int msg,
                                        IntPtr wParam,
                                        ref LVGROUP lParam);
Exemplo n.º 27
0
    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);
      }
    }
Exemplo n.º 28
0
 private static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, ref LVGROUP lParam);
Exemplo n.º 29
0
 private int SendMessage(ListViewMessage msg, int wParam, LVGROUP group) => User32.SendMessage(Handle, msg, wParam, group).ToInt32();
Exemplo n.º 30
0
 public static extern IntPtr SendMessage(HandleRef hWnd,
                                         int msg,
                                         IntPtr wParam,
                                         ref LVGROUP lParam);
Exemplo n.º 31
0
 public static extern IntPtr SendMessage(IntPtr hWnd, int msg, int wParam, ref LVGROUP lParam);
Exemplo n.º 32
0
 private static extern int SendMessage(IntPtr window, int message, int wParam, ref LVGROUP lParam);