Back to Devexpress

PropertyGridControl.CollectionButtonsVisibility Event

wpf-devexpress-dot-xpf-dot-propertygrid-dot-propertygridcontrol-02e8527e.md

latest9.4 KB
Original Source

PropertyGridControl.CollectionButtonsVisibility Event

Allows you to show and hide collection buttons ( Add Item and Remove Item ) based on custom logic.

Namespace : DevExpress.Xpf.PropertyGrid

Assembly : DevExpress.Xpf.PropertyGrid.v25.2.dll

NuGet Package : DevExpress.Wpf.PropertyGrid

Declaration

csharp
public event EventHandler<CollectionButtonsVisibilityEventArgs> CollectionButtonsVisibility
vb
Public Event CollectionButtonsVisibility As EventHandler(Of CollectionButtonsVisibilityEventArgs)

Event Data

The CollectionButtonsVisibility event's data class is CollectionButtonsVisibilityEventArgs. The following properties provide information specific to this event:

PropertyDescription
ButtonKindGets the collection button‘s type. Inherited from CollectionButtonBaseEventArgs.
HandledGets or sets a value that indicates the present state of the event handling for a routed event as it travels the route. Inherited from RoutedEventArgs.
IsVisibleGets or sets whether to display the collection button.
OriginalSourceGets the original reporting source as determined by pure hit testing, before any possible Source adjustment by a parent class. Inherited from RoutedEventArgs.
RoutedEventGets or sets the RoutedEvent associated with this RoutedEventArgs instance. Inherited from RoutedEventArgs.
RowGets a property grid row. Inherited from PropertyGridRowBaseEventArgs.
SourceGets or sets a reference to the object that raised the event. Inherited from RoutedEventArgs.
ValueGets a row’s value. Inherited from PropertyGridRowBaseEventArgs.

The event data class exposes the following methods:

MethodDescription
InvokeEventHandler(Delegate, Object)When overridden in a derived class, provides a way to invoke event handlers in a type-specific way, which can increase efficiency over the base implementation. Inherited from RoutedEventArgs.
OnSetSource(Object)When overridden in a derived class, provides a notification callback entry point whenever the value of the Source property of an instance changes. Inherited from RoutedEventArgs.

Remarks

View Example: Specify Custom Collection Edit Actions

Handle the CollectionButtonsVisibility event to implement custom logic that shows and hides collection buttons. The following code sample hides the Add Item button if the collection contains more than 5 items and hides the Remove Item button for the collection item whose ID is 0:

xaml
<dxprg:PropertyGridControl SelectedObject="{Binding DemoProduct}" 
                           CollectionButtonsVisibility="OnCollectionButtonsVisibility"/>
csharp
using DevExpress.Xpf.PropertyGrid;
// ...

void OnCollectionButtonsVisibility(object sender, CollectionButtonsVisibilityEventArgs e) {
    if (e.ButtonKind == CollectionButtonKind.Add) {
        var collection = (SupplierList)e.Value;
        e.IsVisible = collection.Count <= 5;
    }
    if (e.ButtonKind == CollectionButtonKind.Remove) { 
        var supplier = e.Value as Supplier;
        if (supplier != null && supplier.ID == 0)
            e.IsVisible = false;
    }
}
vb
Imports DevExpress.Xpf.PropertyGrid
' ...

Private Sub OnCollectionButtonsVisibility(ByVal sender As Object, ByVal e As CollectionButtonsVisibilityEventArgs)
    If e.ButtonKind = CollectionButtonKind.Add Then
        Dim collection = CType(e.Value, SupplierList)
        e.IsVisible = collection.Count <= 5
    End If

    If e.ButtonKind = CollectionButtonKind.Remove Then
        Dim supplier = TryCast(e.Value, Supplier)
        If supplier IsNot Nothing AndAlso supplier.ID = 0 Then e.IsVisible = False
    End If
End Sub

Refer to the following help topic for more information: Collection Definitions.

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the CollectionButtonsVisibility event.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

wpf-property-grid-specify-custom-collection-edit-actions/CS/MainWindow.xaml#L10

xml
ShowCategories="Hidden"
CollectionButtonsVisibility="OnCollectionButtonsVisibility"
CollectionButtonClick="OnCollectionButtonClick"/>

wpf-property-grid-specify-custom-collection-edit-actions/CS/obj/Debug/net472/MainWindow.g.cs#L93

csharp
#line 10 "..\..\..\MainWindow.xaml"
this.propertyGrid.CollectionButtonsVisibility += new System.EventHandler<DevExpress.Xpf.PropertyGrid.CollectionButtonsVisibilityEventArgs>(this.OnCollectionButtonsVisibility);

wpf-property-grid-specify-custom-collection-edit-actions/VB/obj/Debug/net8.0-windows/MainWindow.g.vb#L94

vb
#ExternalSource("..\..\..\MainWindow.xaml",10)
AddHandler Me.propertyGrid.CollectionButtonsVisibility, New System.EventHandler(Of DevExpress.Xpf.PropertyGrid.CollectionButtonsVisibilityEventArgs)(AddressOf Me.OnCollectionButtonsVisibility)

See Also

AllowAddItems

AllowRemoveItems

PropertyGridControl Class

PropertyGridControl Members

DevExpress.Xpf.PropertyGrid Namespace