This is a migrated thread and some comments may be shown as answers.

Observable Collection IndexOf() VS2012 Bug?

1 Answer 57 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Robert
Top achievements
Rank 1
Robert asked on 27 Feb 2013, 12:07 AM
Hi,

Firstly I must point out that this is to do with vs2010 and 2012 rather than a telerik product.

I have the following code:

private void treeMenuItemEditProduct_Click(object sender, RadRoutedEventArgs e)
{
 
    if (this.treeProducts.SelectedItem != null)
    {
        RadTreeViewItem treeViewItem = (RadTreeViewItem)treeProducts.SelectedItem;
        Products selectedProduct = treeViewItem.Tag as Products;
 
        EditProductsWindow editProductWindow = new EditProductsWindow(selectedProduct);
        editProductWindow.Owner = Window.GetWindow(this);
        editProductWindow.IsRestricted = true;
        editProductWindow.WindowStartupLocation = WindowStartupLocation.CenterOwner;
        editProductWindow.ShowDialog();
        //Check if the closing window achieved or failed its task
        if (editProductWindow.DialogResult == true)
        {
            //Get collection Index of selected product
            int index = TAS2Database.DBTimers.GetProducts.EnabledProducts.IndexOf(selectedProduct);
            //Remove Selected Product from List
            TAS2Database.DBTimers.GetProducts.EnabledProducts.Remove(selectedProduct);
            //Add new Product to Products List
            TAS2Database.DBTimers.GetProducts.EnabledProducts.Insert(index, editProductWindow.newProduct);
 
            //Amend TreeViewItem
            treeViewItem.Tag = editProductWindow.newProduct;
            treeViewItem.Header = editProductWindow.newProduct.Name.ToString();
            treeViewItem.ToolTip = editProductWindow.newProduct.ID.ToString();
        }
    }
    else
    {
        RadWindow.Alert("Please select a product to edit.");
    }
}


When I execute the following line of code for a second time in VS2012 I get a return value of -1, where as in VS2010 in works fine every time.

//Get collection Index of selected product
int index = TAS2Database.DBTimers.GetProducts.EnabledProducts.IndexOf(selectedProduct);
 
When I say a second time, I mean that I execute the "click" function once and all works well, but when the click executes a second time, then I keep on getting a return value of -1. As I previously mentioned, this problem does not exist when using VS2010.

Does anyone have any ideas of why this may be?

Thank you very much for your time taken to read this and I look forward to any responses that you may have.

Rob





1 Answer, 1 is accepted

Sort by
0
Robert
Top achievements
Rank 1
answered on 27 Feb 2013, 12:35 AM
Ok please ignore this post. It's because my collection is linked to a "refresh" timer, thus the refresh kicks in mid way during my method.
Tags
General Discussions
Asked by
Robert
Top achievements
Rank 1
Answers by
Robert
Top achievements
Rank 1
Share this question
or