New to Telerik UI for WinForms? Start a free 30-day trial
Custom items
Updated over 6 months ago
RadCardView allows you to create and use your own custom visual items. This article demonstrates how to achieve it.
Custom items in RadCardView
This can be done by making use of the CardViewItemCreating event. The following example demonstrates creating a visual item with a checkbox in it. The checkbox itself is an editor and in order to customize it we need to extend the CardViewItem and CardViewEditorItem classes.
Figure 1: CardView With Checkbox

First let's create our custom items:
Creating Custom CardViewItem
C#
public class CheckBoxCardViewItem : CardViewItem
{
protected override void CreateChildElements()
{
base.CreateChildElements();
this.TextSizeMode = LayoutItemTextSizeMode.Proportional;
this.TextProportionalSize = 0;
}
protected override CardViewEditorItem CreateEditorItem()
{
return new CheckBoxEditorItem();
}
public override void Synchronize()
{
CardListViewVisualItem cardVisualItem = this.FindAncestor<CardListViewVisualItem>();
if (this.CardField == null || cardVisualItem == null || cardVisualItem.Data == null)
{
return;
}
RadCheckBoxElement checkBox = ((CheckBoxEditorItem)this.EditorItem).Checkbox;
checkBox.Text = this.CardField.HeaderText;
checkBox.Checked = this.ContainsFeature(cardVisualItem.Data, this.FieldName);
}
private bool ContainsFeature(ListViewDataItem item, string feature)
{
return item[feature] != null && Convert.ToInt32(item[feature]) != 0;
}
}
Creating Custom CardViewEditorItem
C#
public class CheckBoxEditorItem : CardViewEditorItem
{
private RadCheckBoxElement checkbox;
public RadCheckBoxElement Checkbox
{
get { return this.checkbox; }
set { this.checkbox = value; }
}
protected override void CreateChildElements()
{
base.CreateChildElements();
this.checkbox = new RadCheckBoxElement();
this.Children.Add(this.checkbox);
}
}
Back in our form we need to populate some sample data for the checkboxes as well as subscribe and handle the CardViewItemCreating event. For the purpose of this example we are data binding the control to the SofiaCarRental database which is available in the installation folder of the suite.
Use the custom item
C#
private List<string> features;
public CadViewCustomItems()
{
InitializeComponent();
this.features = new List<string>() { "AirConditioner", "Mp3Player", "DVDPlayer", "ABS", "ASR", "Navigation", "Available" };
this.radCardView1.CardViewItemCreating += radCardView1_CardViewItemCreating;
}
private void radCardView1_CardViewItemCreating(object sender, CardViewItemCreatingEventArgs e)
{
CardViewItem cardViewItem = e.NewItem as CardViewItem;
if (cardViewItem != null && this.features.Contains(cardViewItem.FieldName))
{
CheckBoxCardViewItem checkBoxItem = new CheckBoxCardViewItem();
checkBoxItem.FieldName = cardViewItem.FieldName;
e.NewItem = checkBoxItem;
}
}
private void CadViewCustomItems_Load(object sender, EventArgs e)
{
this.carsTableAdapter.Fill(this.sofiaCarRentalDataSet.Cars);
}