SolvedPrivate

Clear ObservableCollection item

Posted on 2014-01-03
3
51 Views
Last Modified: 2016-02-10
I have an Observable Collection Called _items. I use it for a chart for when I add series. Each series has an item  in the collection. I need to clear an item in the collection by selecting the series  on the chart which I am able to do and I get the series name. I am using Linq to iterate through each item in the collection and get that Item. With that  in mind how do I clear that entry. Any help would be greatly appreciated
       private void click_me(object sender, ChartItemClickEventArgs e)
        {
            var filteredData = new List<Item>();
//Get the name of the series to delete
            string legendLabel = e.DataSeries.LegendLabel;
            //string strconfirm = "Confirm Deletion of " + legendLabel;
            //MessageBox.Show(strconfirm);
//run though each item in the collection
            foreach (var item in _items)
            {
                if (item != null)
                {
                    if (item.Count > 0)
                    {
//find it
                        var map = viewchart.SeriesMappings.Where(v => legendLabel == item[0].seriesType).FirstOrDefault();
                        if (map == null)
                            return;
//Clear it here
                        
                    }

                }
            }
           

           
        }

Open in new window

0
Comment
Question by:r3nder
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 39756165
Hi  r3nder;

This should do what you need.

//run though each item in the collection
// I will assume that _items is a collection of data type Item
Item map = null;
foreach (var item in _items)
{
    if (item != null)
    {
        if (item.Count > 0)
        {
            //find it
            map = viewchart.SeriesMappings
                           .Where(v => legendLabel == item[0].seriesType)
                           .FirstOrDefault();
                           
            if (map == null)
                return;
            //Clear it here
            // Can't remove item while you are iterating through the list              
            // So do it outside the foreach loop
        }
    }
}

_items.Remove(map);

Open in new window

0
 
LVL 6

Author Closing Comment

by:r3nder
ID: 39756382
I was trying to  remove it in the find :) thanks man
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 39757367
Not a problem, glad to help out.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Please explain purpose of GZIP 4 59
global Variable - 2 functions in powershell 1 21
C# DataTable (in memory) vs SQL Lookups 4 36
Trigger C# code inside the SQL Server 6 34
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question