tabpage - read-only textbox

Asked

Viewed 102 times

1

Guys good night how are you? I have a form, with a tabpage, and with some textbox, I’m trying to deploy in the page load, that the property isreadonly is true.

but I’m not getting it, I’m using the following condition:

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;
    }

but when executing, the error is returned:

Additional information: Cannot convert a 'System.Windows.Forms.Tabpage' object to 'Devexpress.XtraEditors.Textedit'.

After our friend’s comment, I tried again, but still unsuccessful:

foreach (Control ctl in xtraTabControl1.Controls)

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

Thanks

  • Young man, there is a Devexpress component there that changes a little your scenario :-D

  • Friend, even removing that component, it is not rolling, I did so, and also in:

  • Try using . NET native components in foreach to see if it works... you need a different treatment for Devexpress components

  • Um.. I am using the DX xtraTabcontrol, I will switch to the . net tabcontrol and try. Thank you

  • Even checking if it is a textEdit do you cast? Tried without the cast? What error returns?

  • In the second way, it does not return any error, only that when executing the application, the textedit is not read-only.

Show 1 more comment

1 answer

1


Friends good morning. I managed to solve the problem.

The error was that while doing the loop was mentioning Tabcontrol, however the controls are in Tabpage.

It follows corrected condiment:

foreach (Control ctl in tabPage1.Controls) 
            if (ctl is TextBox)
            {
                ((TextBox)(ctl)).ReadOnly = true;
            }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.