tabpage - textbox read-only

1
Good night guys. How are you? I have a form, with a tabpage, and with some textbox, I'm trying to deploy in the load of the page, that the property isreadonly is true.

But I'm not getting it, I'm using the following link:

private void Comercial_Load(object sender, EventArgs e)
    {
        foreach (Control ctl in tabControl1.Controls)

            if(ctl is TabPage)
            {
                ((DevExpress.XtraEditors.TextEdit)(ctl)).ReadOnly = true;
                ((TextBox)(ctl)).ReadOnly = true;
            }

        xtraTabPage1.PageVisible = false;
        xtraTabPage2.PageVisible = false;
        xtraTabPage3.PageVisible = false;
        xtraTabPage4.PageVisible = false;
    }

however when running, and returned the error:

  

Additional information: Can not convert an object of type 'System.Windows.Forms.TabPage' to type 'DevExpress.XtraEditors.TextEdit'.

After our friend's comment, I tried again, but still unsuccessfully:

foreach (Control ctl in xtraTabControl1.Controls)

            if (ctl is TextEdit)
            {
                ((TextEdit)(ctl)).Enabled = false;
            }

Thanks

    
asked by anonymous 08.07.2016 / 01:52

1 answer

1

Friends, good morning. I was able to solve the problem.

The error was that while doing the loop was mentioning the TabControl, but the controls are in TabPage.

Follow the corrected rule:

foreach (Control ctl in tabPage1.Controls) 
            if (ctl is TextBox)
            {
                ((TextBox)(ctl)).ReadOnly = true;
            }
    
08.07.2016 / 13:48