Completed
Last Updated: 26 Nov 2015 11:33 by ADMIN
ADMIN
Dess | Tech Support Engineer, Principal
Created on: 06 Nov 2015 11:49
Category:
Type: Bug Report
0
FIX. RadListView - ArgumentOutOfRangeException when deleting an item from the DataSource collection
To reproduce: use the following code snippet:

List<Item> items = new List<Item>();

public Form1()
{ 
    InitializeComponent();

    for (int i = 0; i < 10; i++)
    {
        items.Add(new Item("Item" + i));
    }
    this.radListView1.DataSource = items;
    this.radListView1.DisplayMember = "Title";

    this.radButton1.Click += radButton1_Click;
}

public class Item
{
    public string Title { get; set; }
     
    public Item(string title)
    {
        this.Title = title;
    }
}

private void radButton1_Click(object sender, EventArgs e)
{
    if (this.radListView1.SelectedItem != null)
    { 
        items.Remove(this.radListView1.SelectedItem.DataBoundItem as Item); 
        this.radListView1.DataSource = null;
        this.radListView1.DataSource = items;
        this.radListView1.DisplayMember = "Title";
    }
}

Steps:
1. Select the first item and click the button.
2. Select the last item and click the button again. As a result, an ArgumentOutOfRangeException is thrown.

Workaround: use BindingList instead of List
0 comments