0

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;
	}
            
   }
1
Contributor
1
Reply
2
Views
6 Years
Discussion Span
Last Post by fernandofranca
1

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;
        }
Votes + 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.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.