c# Check, if element already exist in flowLayoutPanel

25 Views Asked by At

I have a code that should create user elements in a flowLayoutPanel. But, each element should only exist once.

This is my code:

flowLayoutPanelUser.Controls.Clear();
foreach (Data a in AllData)
{
    if (a != null)
    {
        Button buttonHome = new Button();
        buttonHome.Text = a.User;
        buttonHome.Tag = a.User;

        flowLayoutPanelUser.Controls.Add(buttonHome);

        buttonHome.Click += new EventHandler(OpenUser_Click);
    }
}

AllData is the input.

I am looking for something like this:

if (!toolStripMenuItem.DropDown.Items.Cast<ToolStripMenuItem>().Any(x => x.Text == a.Typ))
{

}

I had already been looking for a solution

0

There are 0 best solutions below