0

i have a dictionary that you can add cards to by searching on a listbox but now i want to be able to remove that item from the dictionary if the user presses a button here is the code i use to add a value to the dictionary

if (!m_banlists[BanList.Items[BanList.SelectedIndex].ToString()].Exists(banListCard => banListCard.ID == Program.CardData[cardid].Id))
{   m_banlists[BanList.Items[BanList.SelectedIndex].ToString()].Add(
                       new BanListCard { ID = Program.CardData[cardid].Id, Banvalue = 0, Name = Program.CardData[cardid].Name });
}

i wont post all the code as its too long heres the code i use to remove an item

var list = (ListBox) sender;
if (list.SelectedIndex != -1)
{
     int cardid = Int32.Parse((string)list.SelectedItem.ToString());
     if (m_banlists[BanList.Items[BanList.SelectedIndex].ToString()].Exists(banListCard => banListCard.ID == Program.CardData[cardid].Id))
     {
         m_banlists[BanList.Items[BanList.SelectedIndex].ToString()].Remove();
         list.Items.RemoveAt(list.SelectedIndex);
     }
}

but i cant figure out what to put in the brackets of remove to find the value oh and it needs to look for the ID value

1 Answer 1

1

I think you can try this

m_banlists[BanList.Items[BanList.SelectedIndex].ToString()].ToList().RemoveAll(x=>x.ID==someId);
Sign up to request clarification or add additional context in comments.

2 Comments

and actually it is set up as a dictionary just set up a bit different to most dictionaries
@outlaw1994 ok, but try to edit your comment instead of adding new ones, to don't spam :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.