Ejemplo n.º 1
0
        private void ExpandOrCollapse(bool collapse)
        {
            CheckControlEnabled();

            // Check if item can be expanded or collapsed.
            bool isCollapsed = IsCollapsed();

            if ((!collapse && !isCollapsed) || (collapse && isCollapsed))
            {
                throw new InvalidOperationException(SR.Get(SRID.OperationCannotBePerformed));
            }

            NativeMethods.LVGROUP group = new NativeMethods.LVGROUP();
            group.Init(Marshal.SizeOf(typeof(NativeMethods.LVGROUP)));
            // Note:  If we set group.mask to LVGF_GROUPID | LVGF_STATE,
            // SetGroupInfo() will fail.  Setting LVGF_STATE alone works, however.
            group.mask      = NativeMethods.LVGF_STATE;
            group.iGroupID  = _groupID;
            group.stateMask = NativeMethods.LVGS_COLLAPSED;
            group.state     = collapse ? NativeMethods.LVGS_COLLAPSED : 0;
            if (!XSendMessage.SetGroupInfo(_hwnd, group))
            {
                throw new InvalidOperationException(SR.Get(SRID.OperationCannotBePerformed));
            }
        }