Completed
Last Updated: 16 Oct 2015 08:00 by ADMIN
ADMIN
Dess | Tech Support Engineer, Sr.
Created on: 14 Oct 2015 10:37
Category:
Type: Bug Report
0
FIX. RadListView - System.InvalidOperationException: Setting parent to an already disposed element when a custom item is used with RadTextBoxElement
To reproduce: use the following code snippet and click the button

public Form1()
{
    InitializeComponent();
    this.radListView1.VisualItemCreating += radListView1_VisualItemCreating;
    this.radListView1.ViewType = ListViewType.DetailsView;
    radListView1.ItemSize = new Size(0, 56);
    Populate();
}

private void radListView1_VisualItemCreating(object sender, ListViewVisualItemCreatingEventArgs e)
{
    e.VisualItem = new CustomDetailListViewVisualItem();
}

private void radButton1_Click(object sender, EventArgs e)
{
    Populate();
}

private void Populate()
{
    this.radListView1.Items.Clear();
    this.radListView1.BeginUpdate();
    for (int i = 0; i < 5; i++)
    {
        ListViewDataItem lvdi = new ListViewDataItem();
       
        if (i == -1 || i > radListView1.Items.Count || radListView1.Items.Count == 0) 
        {
            radListView1.Items.Add(lvdi);
        }
        else
        {
            radListView1.Items.Insert(i, lvdi);
        }
    }
    this.radListView1.EndUpdate();
}

public class CustomDetailListViewVisualItem : DetailListViewVisualItem
{
    RadTextBoxElement tb = new RadTextBoxElement();

    protected override void CreateChildElements()
    {
        base.CreateChildElements();
        this.Children.Add(tb);
    }
    
    protected override Type ThemeEffectiveType     
    { 
        get    
        { 
            return typeof(DetailListViewVisualItem);     
        }
    }
}


Workaround: use RadTextBoxControlElement instaed of RadTextBoxElement.
0 comments