I have the following funtion in my ComboBoxControl class, and it only returns to me the control of the comboBox.

The foreach works fine but my problem is how to return the ComboBox, becuse if the ComboBox doesn´t exists I need to return NULL or something else.

How can I return the ComboBox in this function?

public ComboBox getComboBoxControl(string ComboBoxName)
        {
            ComboBox _bx;
            foreach (Control frmControl in frm.Controls)
            {
                if (frmControl is ComboBox)
                {
                    if (frmControl.Name == ComboBoxName)
                    {
                        _bx = (ComboBox)frmControl;
                        break;
                    }
                   }
                }
            
	if (_bx /* Something like is Set ?? */ )
            {
		return _bx;
            }
	else
	{
		return null;
	}
            
   }

Ok here is the correct code

Solved

public ComboBox getComboBoxControl(string ComboBoxName)
        {
            ComboBox _bx;
            _bx = null;
            foreach (Control frmControl in frm.Controls)
            {
                if (frmControl is ComboBox)
                {
                    if (frmControl.Name == ComboBoxName)
                    {
                        _bx = (ComboBox)frmControl;
                        break;
                    }
                }
            }
            return _bx;
        }
Comments
Thanks for coming back and resolving your post, many people just leave dead ends on the forum when they find thier own answer, Thanks for not being one of them.
This question has already been answered. Start a new discussion instead.