?
SolvedPrivate

Clear ObservableCollection item

Posted on 2014-01-03
3
Medium Priority
?
53 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 2000 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

Technology Partners: 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

A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

752 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