-1

Im trying to Double Click on a Label in a FlowLayoutPanel, The labels are created dynamically. Im trying to open the form using this

foreach(Label label in myFlp )
{
    var Id = label.Name.ToString();
    int personID;
    if (!String.IsNullOrWhiteSpace(Id) && int.TryParse(Id, out personID))
    {
        FrmAddress frmAddress = new FrmAddress(_controller, personID);
        frmAddress.ShowDialog();
        frmAddress.Dispose();
    }
}

Getting this error;

foreach statement cannot operate on variables of type 'System.Windows.Forms.FlowLayoutPanel' because 'System.Windows.Forms.FlowLayoutPanel' does not contain a public definition for 'GetEnumerator'    
Daniel
  • 9,491
  • 12
  • 50
  • 66
AndroidAL
  • 1,111
  • 4
  • 15
  • 35

1 Answers1

1

Try something like this :

foreach(var control in myFLp.Controls)
{
    if(control is Label)
    var Id = (Label)control.Name.ToString();
    int personID;

    if (!String.IsNullOrWhiteSpace(Id) && int.TryParse(Id, out personID))
    {
        FrmAddress frmAddress = new FrmAddress(_controller, personID);
        frmAddress.ShowDialog();
        frmAddress.Dispose();
    }
}