0

enter image description here

I tried to show items without duplicate in List Box.

private void Lst_Box_SelectedIndexChanged(object sender, EventArgs e)
{
    if (Chk_Multi.Checked == true)
    {
        Lst_Box.SelectionMode = SelectionMode.MultiSimple;
        if (Lst_Box.SelectedItem == "Janvier")
        {
            Lst_Selected.Items.Add(Lst_Box.Text);
        }
    }
    if (Chk_Multi.Checked == false)
    {
        Lst_Box.SelectionMode = SelectionMode.One;
        Lst_Selected.Items.Add(Lst_Box.Text);
    }
}
πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
Fatihi Youssef
  • 411
  • 1
  • 6
  • 15
  • 1
    write code that will search the Listbox using `.Contains()` method you need to check the value if it exist first before adding to the ListBox very simple task to do.. – MethodMan Feb 21 '16 at 00:58

2 Answers2

2
if(!Lst_Selected.Items.Contains(Lst_Box.Text)
{
  Lst_selected.Items.Add(Lst_Box.Text);
}
Bogey
  • 4,926
  • 4
  • 32
  • 57
1

You could use the Except extension method... example..

int[] foo = new int[]{1,2,3};
int[] bar = new int[]{1,3};

IEnumerable<int> fooMinusBar = foo.Except(bar);
IEnumerable<int> barMinusFoo = bar.Except(foo);

enter image description here

Aydin
  • 15,016
  • 4
  • 32
  • 42