I am using a default RadListView control, and wish to use custom list items. Following the directions here, I wrote the following class.
using System;
using System.Drawing;
using Telerik.WinControls.UI;
using Telerik.WinControls.Layouts;
namespace CustomListItemTest
{
class SampleVisualItem : SimpleListViewVisualItem
{
private LightVisualElement sampleNumberField;
private StackLayoutPanel stackPanel;
public string sampleNumber = string.Empty;
protected override void CreateChildElements()
{
base.CreateChildElements();
stackPanel = new StackLayoutPanel
{
Orientation = System.Windows.Forms.Orientation.Horizontal,
EqualChildrenWidth = true,
ShouldHandleMouseInput = false,
NotifyParentOnMouseInput = true
};
sampleNumberField = new LightVisualElement
{
StretchHorizontally = true,
MinSize = new Size(50, 0),
ShouldHandleMouseInput = false,
NotifyParentOnMouseInput = true
};
stackPanel.Children.Add(sampleNumberField);
Children.Add(stackPanel);
}
protected override void SynchronizeProperties()
{
base.SynchronizeProperties();
Text = "";
sampleNumberField.Text = sampleNumber;
}
protected override Type ThemeEffectiveType
{
get
{
return typeof(SimpleListViewVisualItem);
}
}
}
}
On the form I handle these events.
private void RadForm1_Load(object sender, EventArgs e)
{
ListViewDataItem newItem = new ListViewDataItem();
newItem.Key = "sampleNumber";
newItem.Value = "123434";
SampleList.Items.Add(newItem);
}
private void SampleList_VisualItemCreating(object sender, ListViewVisualItemCreatingEventArgs e)
{
if (SampleList.ViewType == ListViewType.ListView)
{
e.VisualItem = new SampleVisualItem();
}
}
However the added item does not appear. If I click around enough and move the mouse off screen, the item does appear (so it does exist), but if I click off-screen again it's gone.
What am I doing wrong?