private void SetGrpState(ListViewGroup lvGroup, ListViewGroupState grpState, string task)
        {
            if (OSVersion.IsBelow(WindowsVersion.Vista))
            {
                return;
            }
            if (lvGroup == null || lvGroup.ListView == null)
            {
                return;
            }
            if (lvGroup.ListView.InvokeRequired)
            {
                lvGroup.ListView.BeginInvoke(new CallBackSetGroupState(SetGrpState), lvGroup, grpState, task);
            }
            else
            {
                int?    GrpId  = GetGroupID(lvGroup);
                int     gIndex = lvGroup.ListView.Groups.IndexOf(lvGroup);
                LVGroup group  = new LVGroup();
                group.CbSize = LVGroup.SizeOf;

                if (!string.IsNullOrEmpty(task))
                {
                    group.Mask =
                        ListViewGroupMask.Task |
                        ListViewGroupMask.State |
                        ListViewGroupMask.Align;

                    group.Task    = task;
                    group.CchTask = task.Length;
                }
                else
                {
                    group.Mask = ListViewGroupMask.State;
                }

                group.GroupState = grpState;

                if (GrpId != null)
                {
                    group.GroupId = GrpId.Value;
                    SendMessage(this.Handle, LVM_SetGroupInfo, GrpId.Value, ref group);
                }
                else
                {
                    group.GroupId = gIndex;
                    SendMessage(this.Handle, LVM_SetGroupInfo, gIndex, ref group);
                }

                lvGroup.ListView.Refresh();
            }
        }
        private void SetGrpState(ListViewGroup lvGroup, ListViewGroupState grpState, string task)
        {
            if (OSVersion.IsBelow(WindowsVersion.Vista))
            {
                return;
            }
            if (lvGroup == null || lvGroup.ListView == null)
            {
                return;
            }
            if (lvGroup.ListView.InvokeRequired)
            {
                lvGroup.ListView.Invoke(new CallBackSetGroupState(SetGrpState), lvGroup, grpState, task);
            }
            else
            {
                int?    GrpId  = GetGroupID(lvGroup);
                int     gIndex = lvGroup.ListView.Groups.IndexOf(lvGroup);
                LVGroup group  = new LVGroup();
                group.CbSize = Marshal.SizeOf(group);
                group.Mask  |= ListViewGroupMask.Task
                               | ListViewGroupMask.State
                               | ListViewGroupMask.Align;

                IntPtr taskString = Marshal.StringToHGlobalAuto(task);

                if (task.Length > 1)
                {
                    group.Task    = taskString;
                    group.CchTask = task.Length;
                }

                group.GroupState = grpState;

                if (GrpId != null)
                {
                    group.GroupId = GrpId.Value;
                    SendMessage(base.Handle, LVM_SetGroupInfo, GrpId.Value, ref group);
                }
                else
                {
                    group.GroupId = gIndex;
                    SendMessage(base.Handle, LVM_SetGroupInfo, gIndex, ref group);
                }
                lvGroup.ListView.Refresh();

                Marshal.FreeHGlobal(taskString);
            }
        }
 private static extern IntPtr SendMessage(IntPtr hWnd, int Msg, int wParam, ref LVGroup lParam);
        private void SetGrpState(ListViewGroup lvGroup, ListViewGroupState grpState, string task)
        {
            if (OSVersion.IsBelow(WindowsVersion.Vista))
                return;
            if (lvGroup == null || lvGroup.ListView == null)
                return;
            if (lvGroup.ListView.InvokeRequired)
                lvGroup.ListView.BeginInvoke(new CallBackSetGroupState(SetGrpState), lvGroup, grpState, task);
            else
            {
                int? GrpId = GetGroupID(lvGroup);
                int gIndex = lvGroup.ListView.Groups.IndexOf(lvGroup);
                LVGroup group = new LVGroup();
                group.CbSize = LVGroup.SizeOf;

                if (!string.IsNullOrEmpty(task))
                {
                    group.Mask =
                        ListViewGroupMask.Task |
                        ListViewGroupMask.State |
                        ListViewGroupMask.Align;

                    group.Task = task;
                    group.CchTask = task.Length;
                }
                else
                {
                    group.Mask = ListViewGroupMask.State;
                }

                group.GroupState = grpState;

                if (GrpId != null)
                {
                    group.GroupId = GrpId.Value;
                    SendMessage(this.Handle, LVM_SetGroupInfo, GrpId.Value, ref group);
                }
                else
                {
                    group.GroupId = gIndex;
                    SendMessage(this.Handle, LVM_SetGroupInfo, gIndex, ref group);
                }

                lvGroup.ListView.Refresh();
            }
        }
 private static extern IntPtr SendMessage(IntPtr hWnd, int Msg, int wParam, ref LVGroup lParam);
        private void SetGrpState(ListViewGroup lvGroup, ListViewGroupState grpState, string task)
        {
            if (OSVersion.IsBelow(WindowsVersion.Vista))
                return;
            if (lvGroup == null || lvGroup.ListView == null)
                return;
            if (lvGroup.ListView.InvokeRequired)
                lvGroup.ListView.Invoke(new CallBackSetGroupState(SetGrpState), lvGroup, grpState, task);
            else
            {
                int? GrpId = GetGroupID(lvGroup);
                int gIndex = lvGroup.ListView.Groups.IndexOf(lvGroup);
                LVGroup group = new LVGroup();
                group.CbSize = Marshal.SizeOf(group);
                group.Mask |= ListViewGroupMask.Task 
                    | ListViewGroupMask.State 
                    | ListViewGroupMask.Align;

                IntPtr taskString = Marshal.StringToHGlobalAuto(task);

                if (task.Length > 1)
                {
                    group.Task = taskString;
                    group.CchTask = task.Length;
                }

                group.GroupState = grpState;
          
                if (GrpId != null)
                {
                    group.GroupId = GrpId.Value;
                    SendMessage(base.Handle, LVM_SetGroupInfo, GrpId.Value, ref group);
                }
                else
                {
                    group.GroupId = gIndex;
                    SendMessage(base.Handle, LVM_SetGroupInfo, gIndex, ref group);
                }
                lvGroup.ListView.Refresh();

                Marshal.FreeHGlobal(taskString);
            }
        }