Scroll property grid item into view

Grids for WPF Forum

Posted 13 years ago by Max Palmer
Version: 11.1.0543
Avatar
I'm adding support for undo / redo to our application and have hit an issue with the property grid. Usually, when a user undoes / redoes a change the application attempts to ensure that the data that has changed is visible to the user. To be able to do this, I need to ensure that when a property change is undone, the property in the data grid is visible. Unfortunately, I can't find an appropriate method. ListView controls have ScrollIntoView() methods, while TreeViews have EnsureVisible. Is there any way of doing this with the ActiPro property grid?

Comments (4)

Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Max,

Our PropertyGrid control extends the TreeView control, so the EnsureVisible method should work the same way. The PropertyGridDataAccessorItem in analogous to the TreeViewItem, and actually derives from it.


Actipro Software Support

Posted 13 years ago by Max Palmer
Avatar
Given access to the property grid in my code behind and the fact that I can find the CustomDataPropertyAccessor for the item I want to select, how can I get the PropertyGridDataAccessorItem for the CustomDataPropertyAccessor?

I've just spent all morning trying to do this and have run out of options. Any help would be appreciated.

Max
Posted 13 years ago by Max Palmer
Avatar
I've done this by casting the control to a treeview and then using (PropertyGridDataAccessorItem)propertyGridAsTreeView.ItemContainerGenerator.ContainerFromIndex(i) to look for the item. I should be able to use ContainerFromItem, but I couldn't get it to work.

NB I had to do some recursive searching.
Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Max,

The Setting Focus QuickStart shows how you can find the associated PropertyGridDataAccessorItem. You shouldn't have to cast the PropertyGrid to a TreeView, as it derives from TreeView. So anything you can access on the TreeView would be available on the PropertyGrid as well.

You would probably want to adapt the SelectProperty method to accept your CustomDataPropertyAccessor, instead of a property name. But it would look something like:
private static void SelectProperty(ItemsControl control, PropertyDataAccessor propertyDataAccessor) {

    // If the control has not generated it's containers, then we need to delay our call until it does.
    if (control.ItemContainerGenerator.Status == GeneratorStatus.ContainersGenerated) {

        // Determine if this control contains the given property
        if (control.Items.Contains(propertyDataAccessor)) {

            // Get the container for the specified item
            PropertyGridDataAccessorItem container = (PropertyGridDataAccessorItem)control.ItemContainerGenerator.ContainerFromItem(propertyDataAccessor);
            if (container != null) {

                // Select and focus the item
                container.IsSelected = true;
                container.BringIntoView();

                UIElement element = VisualTreeHelperExtended.GetFirstFocusableDescendant(container);
                if (element != null)
                    element.Focus();
            }
        }
        else {
            // Drill into categories and look for property
            foreach (object item in control.Items) {

                // Get the container for the specified item
                PropertyGridDataAccessorItem container = (PropertyGridDataAccessorItem)control.ItemContainerGenerator.ContainerFromItem(item);
                if (container != null && container.DataAccessorType == DataAccessorType.Category)
                    SelectProperty(container, propertyDataAccessor);
            }
        }
    }
    else {
        control.Dispatcher.BeginInvoke(DispatcherPriority.Loaded, (DispatcherOperationCallback)delegate(object arg) {
            SelectProperty(control, propertyDataAccessor);
            return null;
        }, null);
    }
}


Actipro Software Support

The latest build of this product (v24.1.3) was released 24 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.