private void listViewResults_ItemDrag(object sender, ItemDragEventArgs e) { List<int> cardIDs = new List<int>(); foreach (ListViewItem item in listViewResults.SelectedItems) { if(item is IDListViewItem) cardIDs.Add(((IDListViewItem)item).ID); } if (cardIDs.Count > 0) { LanguageData dataLayer = new LanguageData(); string description = string.Empty; foreach (dsLanguageData.CardRow card in dataLayer.GetCardsByIDs(cardIDs)) { description += ", " + card.Question; } description = description.Remove(0, 2); DoDragDrop(new CardDragDropHolder(this, cardIDs, description, CardDragDropAction.Add), DragDropEffects.All); } }
private void CardListPlayList_DragDrop(object sender, DragEventArgs e) { string[] formats = e.Data.GetFormats(); bool wasEmpty = Cards.Count < 1; if (e.Data.GetData(formats[0]) is CardDragDropHolder) { //Add the card to the list LanguageData dataLayer = new LanguageData(); CardDragDropHolder tmp = e.Data.GetData(formats[0]) as CardDragDropHolder; dsLanguageData.CardDataTable dtNewCards = dataLayer.GetCardsByIDs(tmp.CardIDs); if (tmp.Action == CardDragDropAction.Add) AddOrLoadCards(dtNewCards, tmp.Description, tmp.CardListIDs, AddOrLoad.Add); else AddOrLoadCards(dtNewCards, tmp.Description, tmp.CardListIDs, AddOrLoad.Load); } }
/// <summary> /// Refreshes all the loaded cards without getting the from the DB /// </summary> /// <param name="fromDB"></param> public void RefreshCards(bool fromDB) { listView.Items.Clear(); if (fromDB && Cards.Rows.Count > 0) { try { LanguageData dataLayer = new LanguageData(); _cards = dataLayer.GetCardsByIDs(_cards.GetIDList()); } catch (FileNotFoundException e) { //TODO send a message here that the main form will pick up and display on the bottom } } foreach (dsLanguageData.CardRow row in Cards) { listView.Items.Add(new IDListViewItem(row.ID, getDisplayText(row))); } listView.Refresh(); }