Check for flowLayoutPanel in C #

I want to make an error label when my flowLayoutPanel is empty, but I do not know how to verify that flowLayoutPanel is empty. This is my current code:

private void flowLayoutPanel1_ControlRemoved(object sender, ControlEventArgs e)
        {
            if (flowLayoutPanel1.Controls == null)
            {
                customtoolwarning.Visible = true;
            }
            else
            {
                customtoolwarning.Visible = false;
            }
        }

Please, help,

thank

+3
source share
3 answers
private void flowLayoutPanel1_ControlRemoved(object sender, ControlEventArgs e)
        {
            if (flowLayoutPanel1.Controls.Count > 0)
            {
                customtoolwarning.Visible = true;
            }
            else
            {
                customtoolwarning.Visible = false;
            }
        }
+3
source

The problem you are facing is checking Controlson nullto determine if it is empty. The property Controlswill never be null, but instead will be nonempty and has a length of 0 when empty. for instance

if (flowLayoutPanel1.Controls.Count == 0) {
  // It empty
}
+2
source
lblNoContacts.Visible = (flowLayoutPanel.Controls.Count == 0) ? true : false;
0
source

Source: https://habr.com/ru/post/1776744/


All Articles