i have 2 errors in my code and can not figure out how to solve this.
This is my code:
private void add_button_Click(object sender, EventArgs e)`
{
try
{
if (list_selected.Contains(List_selection.SelectedItem))
{
MessageBox.Show("Can't add the same type twice");
}
else
{
list_selected.Items.Add(List_selection.SelectedItem);
}
}
catch
{
{
MessageBox.Show("No type selected");
}
}
}
These are the errors:
Error 1
The best overloaded method match for 'System.Windows.Forms.Control.Contains(System.Windows.Forms.Control)' has some invalid arguments
Error 2
Argument 1: cannot convert from 'object' to 'System.Windows.Forms.Control' C:\Projects\flashloader2013\mainapplication\Form1.cs 467 44 Main
Please help me. ]
List_selection
and list_selected
are ListBoxes
.
You need to write:
if (list_selected.Items.Contains(List_selection.SelectedItem))
Otherwise you check the controls collection of the listView/Listbox (whatever control that could contain other controls)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With