private void itemAddToFavorites_Click(object sender, EventArgs e) { //ListViewItem selectedItem = marketListView.SelectedItems[0]; Market rightClickMarket = markets[marketListView.FocusedItem.Name]; // Add to favorites. var item = new ListViewItem(rightClickMarket.Description); item.Name = rightClickMarket.Description; item.ImageKey = "market"; favoritesListView.Items.Add(item); // Add to the Favorites List we maintain behind the scenes. favoritesList.Add(rightClickMarket); //api.SaveXmlMarketList(MarketListFromListView(favoritesListView), APIMain.GetAPIDirectory("XML") + "MarketListFavorites.xml"); api.SaveXmlMarketList(favoritesList, APIMain.GetAPIDirectory("XML") + "MarketListFavorites.xml"); }
public APIMarketSelectForm() { try { InitializeComponent(); api = APIMain.Instance; exchanges = api.GetExchangeDictionary(); selectedExchange = null; selectedContract = null; selectedMarket = null; DialogResult = DialogResult.Abort; // Start off in List view. toolStripMenuItem4.Checked = true; previouslySelectedMenuItem = toolStripMenuItem4; marketListView.View = View.List; // Load Favorites from Xml file. favoritesList = api.LoadXmlMarketList(APIMain.GetAPIDirectory("XML") + "MarketListFavorites.xml"); // Store these Favorites for easy use and access. favoritesMarkets = new Dictionary <string, Market>(); foreach (Market market in favoritesList) { favoritesMarkets[market.Description] = market; } // And display the favorites on the FavoritesListView. PopulateListView(favoritesListView, favoritesList); currentlyViewing = MarketSelectViewType.EXCHANGES; UpdateDisplay(); } catch (Exception ex) { ExceptionHandler.TraceException(ex); } }