Example #1
0
        public void ExpandProperty(PropertyEnumerator propEnum, bool expand)
        {
            if (propEnum == propEnum.RightBound)
                return;

            Property property = propEnum.Property;

            // Do nothing if the expand state won't change
            if (expand == property.Expanded)
                return;

            InvalidateVisibleItemCount();

            // Hide the inplace control if it is a child of the closed category
            if (property.Expanded && !expand)
            {
                if (SelectedPropertyEnumerator.IsDescendantOf(propEnum))
                    SelectProperty(propEnum);

                if (FirstDisplayedProperty.IsDescendantOf(propEnum))
                    FirstDisplayedProperty = propEnum.GetVisibleDeepEnumerator();
            }

            property.ExpandedInternal = expand;

            _parentCtrl.OnPropertyExpanded(new PropertyExpandedEventArgs(propEnum, expand));

            if (IsHandleCreated)
            {
                // We call OnSizeChanged here because this method checks to see if there
                // is some space left at the bottom of the grid and scrolls it accordingly.
                // It also calls CheckScrollbar()
                Rectangle rect = ClientRectangle;
                OnSizeChanged(rect.Width, rect.Height);

                Invalidate();
            }
        }
Example #2
0
        public bool EnsureVisible(PropertyEnumerator propEnum)
        {
	        if (propEnum == propEnum.RightBound)
		        return false;

	        if (_displayMode == PropertyGrid.DisplayModes.Categorized)
	        {
		        // Ensure that all ancestors are expanded and visible
                PropertyEnumerator parentEnum = propEnum;
                while(parentEnum.HasParent)
                {
                    parentEnum = parentEnum.Parent;
                    if (parentEnum.Property.Expanded == false)
                    {
                        ShowProperty(parentEnum, true);
                        ExpandProperty(parentEnum, true);
                    }
                }
	        }

	        Rectangle itemRect = GetAbsoluteItemRect(propEnum);
	        Rectangle clientRect = ClientRectangle;

	        // Make the item the first visible one at the top if it is above the control
	        if (itemRect.Top < clientRect.Top)
	        {
                _firstDisplayedLine = 1;
		        FirstDisplayedProperty = propEnum.GetVisibleDeepEnumerator();
	        }
	        // Make the item the last visible one at the bottom if it is below the control
	        else
	        {
		        while(itemRect.Bottom > clientRect.Bottom)
		        {
                    Win32Calls.SendMessage(Handle, Win32Calls.WM_VSCROLL, Win32Calls.MakeLong(Win32Calls.SB_LINEDOWN, 0), 0);
			        itemRect = GetAbsoluteItemRect(propEnum);
		        }
                Win32Calls.SendMessage(Handle, Win32Calls.WM_VSCROLL, Win32Calls.MakeLong(Win32Calls.SB_ENDSCROLL, 0), 0);
            }

	        // We call OnSizeChanged here because this method checks to see if there
	        // is some space left at the bottom of the grid and scrolls it accordingly.
	        // It also calls CheckScrollbar()
	        OnSizeChanged(clientRect.Width, clientRect.Height);
            Refresh();

	        return true;
        }
Example #3
0
        private void SelectProperty(PropertyEnumerator enumerator, Point mousePos)
        {
            if ((enumerator.Property != null) && (CheckPropertyVisibility(enumerator) == false))
                throw new ArgumentException("The property enumerator passed to SelectProperty must point to a visible property.", "enumerator");

	        // Clear multi selected items
	        bool multiSelectionCleared = false;
	        if (!_clickWithControl && (_multiSelectedItems.Count > 0))
	        {
                foreach(PropertyVisibleDeepEnumerator currentEnum in _multiSelectedItems)
		        {
                    if (currentEnum != _selectedPropertyEnum)
                        currentEnum.Property.SelectedInternal = false;
                }

		        _multiSelectedItems.Clear();
		        multiSelectionCleared = true;
	        }

            bool selectedPropertyChanged = ((_selectedPropertyEnum != enumerator) || multiSelectionCleared);
            PropertyEnumerator previousSelectedPropertyEnum = _selectedPropertyEnum;

            if ((enumerator != enumerator.RightBound) && (enumerator.RightBound != null))
            {
                if (selectedPropertyChanged)
                {
                    if (_selectedPropertyEnum != _selectedPropertyEnum.RightBound)
                        _selectedPropertyEnum.Property.SelectedInternal = false;

                    _selectedPropertyEnum = enumerator.GetVisibleDeepEnumerator();

                    if (IsHandleCreated)
                    {
                        Rectangle clientRect = ClientRectangle;
                        Rectangle rect = GetItemRect(enumerator);

                        // Show the inplace control, even if partially visible
                        if ((rect.Top < clientRect.Bottom) && (rect.Bottom > clientRect.Top))
                            ShowInPlaceControl(enumerator, mousePos);
                    }

                    if (selectedPropertyChanged)
                        _selectedPropertyEnum.Property.SelectedInternal = true;
                }
                else
                {
                    // If the selected property didn't change we must still ensure that the text will be selected
                    // if the navigation mode says so
                    if ((_parentCtrl.NavigationKeyMode == PropertyGrid.NavigationKeyModes.TabKey) &&
                        ((_parentCtrl.TabKeyNavigationMode & PropertyGrid.TabKeyNavigationModes.TabKeyWithAutoFocus) != 0))
                    {
                        if (_currentInPlaceControl != null)
                        {
                            if (!_currentInPlaceControl.ContainsFocus)
                                FocusTextBox();
                            SelectAllText();
                        }
                    }
                }
            }
		    else if (selectedPropertyChanged)	// No item selected
		    {
                if (IsHandleCreated)
                {
				    // We hide the in-place control
    			    HideInPlaceControl();
			    }

                if (_selectedPropertyEnum.Property != null)
                    _selectedPropertyEnum.Property.SelectedInternal = false;

                _selectedPropertyEnum = enumerator.GetVisibleDeepEnumerator();
            }

            if (selectedPropertyChanged)
            {
                if (IsHandleCreated)
                {
                    if (_parentCtrl.CommentsVisibility)
                        _parentCtrl.Refresh();
                    else
                        Refresh();
                }

                // Notify the derived class
                if (_selectedPropertyEnum != RightBound)
                    _parentCtrl.OnPropertySelected(new PropertySelectedEventArgs(_selectedPropertyEnum,
                        previousSelectedPropertyEnum));
            }
        }