Back to Devexpress

PropertyGridControl.CollectionButtonClick Event

wpf-devexpress-dot-xpf-dot-propertygrid-dot-propertygridcontrol-c4b4b838.md

latest9.1 KB
Original Source

PropertyGridControl.CollectionButtonClick Event

Occurs when a user clicks a collection button. This event allows you to override the button’s default action.

Namespace : DevExpress.Xpf.PropertyGrid

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

NuGet Package : DevExpress.Wpf.PropertyGrid

Declaration

csharp
public event EventHandler<CollectionButtonClickEventArgs> CollectionButtonClick
vb
Public Event CollectionButtonClick As EventHandler(Of CollectionButtonClickEventArgs)

Event Data

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

PropertyDescription
ButtonKindGets the collection button‘s type. Inherited from CollectionButtonBaseEventArgs.
DefaultActionGets the collection button‘s default action.
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.
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

You can use the CollectionButtonClick event to initialize a new item whose values depend on the other item’s values. To do this, pass the created item to the e.DefaultAction property as a parameter.

The following code sample adds a new item with the specified ID property when a user clicks the Add Item button:

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

void OnCollectionButtonClick(object sender, CollectionButtonClickEventArgs e) {
    if (e.ButtonKind == CollectionButtonKind.Add) {
        var collection = (SupplierList)e.Value;
        e.DefaultAction(new Supplier() { ID = collection.Count == 0 ? 0 : collection.Max(x => x.ID) + 1, Name = "", Phone = "" });
        e.Handled = true;
    }
}
vb
Imports DevExpress.Xpf.PropertyGrid
' ...

Private Sub OnCollectionButtonClick(ByVal sender As Object, ByVal e As CollectionButtonClickEventArgs)
    If e.ButtonKind = CollectionButtonKind.Add Then
        Dim collection = CType(e.Value, SupplierList)
        e.DefaultAction(New Supplier() With {
            .ID = If(collection.Count = 0, 0, collection.Max(Function(x) x.ID) + 1),
            .Name = "",
            .Phone = ""
        })
        e.Handled = True
    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 CollectionButtonClick 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#L11

xml
CollectionButtonsVisibility="OnCollectionButtonsVisibility"
                               CollectionButtonClick="OnCollectionButtonClick"/>
</dx:ThemedWindow>

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

csharp
#line 11 "..\..\..\MainWindow.xaml"
this.propertyGrid.CollectionButtonClick += new System.EventHandler<DevExpress.Xpf.PropertyGrid.CollectionButtonClickEventArgs>(this.OnCollectionButtonClick);

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

vb
#ExternalSource("..\..\..\MainWindow.xaml",11)
AddHandler Me.propertyGrid.CollectionButtonClick, New System.EventHandler(Of DevExpress.Xpf.PropertyGrid.CollectionButtonClickEventArgs)(AddressOf Me.OnCollectionButtonClick)

See Also

PropertyGridControl Class

PropertyGridControl Members

DevExpress.Xpf.PropertyGrid Namespace