Custom items
RadListView allows you to create and use your own custom visual items. This article demonstrates how to achieve it.
Custom items in ListView ViewType
This can be done by making use of the VisualItemCreating event. The following example demonstrates creating a visual item with two buttons in it.
Figure 1: Custom SimpleListViewVisualItem
First let's create a custom visual item by inheriting from the SimpleListViewVisualItem class:
Creating custom item
To use the newly created items, you should handle the VisualItemCreating event as shown below:
Use the Custom Item
Custom items in IconsView ViewType
Figure 2: Custom IconListViewVisualItem
We should create a custom visual item inheriting the IconListViewVisualItem. The following example demonstrates how to add custom elements to the IconListViewVisualItem.Children collection:
Creating custom item
To use the newly created item, you should subscribe to the VisualItemCreating event and replace the default item with your custom one:
Custom Items in DetailsView ViewType
Since the DetailsView provides a grid-like interface, it displays a cell for each data field. In order to create custom cells you need to subscribe to the CellCreating event and replace the default DetailListViewDataCellElement with your own cell implementation.
Figure 3: Custom DetailListViewDataCellElement
First let's populate RadListView with items and set its ViewType property to DetailsView:
Now let`s create our custom cell element containing a RadButtonElement. Additionally, we should inherit the DetailListViewDataCellElement class:
Due to the virtualization mechanism of the RadListView control, the default cell of the control is compatible with all columns. When the control is scrolled, the default cell could override the custom one. To apply the custom cell when the control is scrolled is necessary to create another DetailListViewDataCellElement which is not compatible with your custom item.
Finally, we should handle the CellCreating event and substitute the default cell element with our own or return the default cell for the other columns: