Hans Rudel
Hans Rudel

Reputation: 3611

Combobox.Visible property not working

Evening, I have the following code, in a static class which helps my userInterface partial class. Whenever i get to the the section which checks if either the combobox/textbox is visible:

if (cb.Visible == true)

&

if (tb.Visible == true)

its always false even if the controls are visible on the form.

Any ideas?

Thanks

public static bool VerifyTableLayoutControlsContainData(TableLayoutPanel tlp)
    {
        foreach (Control input in tlp.Controls)
        {
            ComboBox cb = input as ComboBox;
            if(cb != null)
            {
                if (cb.Visible == true)
                {
                    if (string.IsNullOrEmpty(cb.SelectedItem.ToString()))
                    {
                        return false;
                    }
                }
            }

            TextBox tb = input as TextBox;
            if (tb != null)
            {
                if (tb.Visible == true)
                {
                    if (string.IsNullOrEmpty(tb.Text))
                    {
                        return false;
                    }
                }
            }
        }
        return true;
    }

Screenshot

Edit1:

UserInterface code

    private void uiBtnDataVerification_Click(object sender, EventArgs e)
    {
        if (VerifyingData != true)
        {
            AllInputsContainDataCsvFileVerificationStage = true;
            //Check all inputs have something in them
            InputsContainDataCsvFileVerificationStage();

            if (AllInputsContainDataCsvFileVerificationStage == false)
            {
                UiHelper.UpdateLog("One or more inputs has not been specified.", uiTxtOperationLog);
                return;
            }

            ...
        }
        else
        {
            //Cancel permanent cancellation token.
        }
    }

    public void InputsContainDataCsvFileVerificationStage()
    {

        ....

        if (UiHelper.VerifyTableLayoutControlsContainData(uiTableLayoutPanelColumnDataTypes)) { }
        else
        {
            AllInputsContainDataCsvFileVerificationStage = false;
        }

        ....
    }

Original code is in the UiHelper class

Edit2: As per Toms suggestion i have made the following changes

public userInterface()
    {
        InitializeComponent();

        uiTableLayoutPanelColumnDataTypes.VisibleChanged += new EventHandler(notifyMe);
        uiCBColumn1DataType.VisibleChanged += new EventHandler(notifyMe1);

        SortedColumnNames = new List<TextBox>();
        SortedDataTypes = new List<ComboBox>();
        AllInputsContainDataCsvFileVerificationStage = true;
    }

    public void notifyMe1(object sender, EventArgs e)
    {
        bool temp = uiCBColumn1DataType.Visible;
        MessageBox.Show("its been changed");
    }

    public void notifyMe(object sender, EventArgs e)
    {
        bool temp = uiTableLayoutPanelColumnDataTypes.Visible;
        MessageBox.Show("its been changed");
    }

before clicking the button, i checed what cb1 visibility property was set to and it was True. I still get false when i try to check via the original method.

im stumped!!

Edit3:

It seems that when i click on the second tab, the comboBox's visible property = false.

Does anyone know why this might be??

Upvotes: 4

Views: 3029

Answers (1)

LarsTech
LarsTech

Reputation: 81675

From my comment:

The TableLayoutPanel control has to be visible on the screen when you run your verification code. If it's behind an inactive TabPage, then it isn't on the screen and the control will report the Visible property as false, regardless if the property is set to true in the designer.

Upvotes: 6

Related Questions