Enable tab in Readonly = true fields | Visual Studio

Asked

Viewed 45 times

0

Hello,

I have this code in the Combobox event, when I select who is a Physical person it enables the relevant fields and blocks those of "Legal" person and vice versa. However it is still possible to pass over the disabled fields by tabulation/ or by clicking however.. (I can’t type anything << is right.).

private void cbTipoPessoa_SelectedIndexChanged(object sender, EventArgs e)
{
    //Irá verificar entre as duas opções disponíves e habilitar ou desabilitar os campos;

    string opcaoSelecionada = cbTipoPessoa.SelectedItem.ToString(); //Irá pegar o valor que está selecionado

    if(opcaoSelecionada == "Física")
    {
        //Campos Jurídicos ficam como leitura somente

        mskCNPJ.ReadOnly = true;
        txtInscricaoEstadual.ReadOnly = true;
        txtInscricaoMunicipal.ReadOnly = true;

        //Campos Físicos habilitados
        mskCPF.ReadOnly = false;
    }else if(opcaoSelecionada == "Jurídica")
    {
        //Campos Físicos ficam como leitura somente
        mskCPF.ReadOnly = true;

        //Campos Jurídicos habilitados
        mskCNPJ.ReadOnly = false;
        txtInscricaoEstadual.ReadOnly = false;
        txtInscricaoMunicipal.ReadOnly = false;
    }
}

What can I do to resolve it? Thank you!

1 answer

1


To the TAB not focus on the element use:

txtMeuControle.TabStop = false;

Even so it will still be possible to click and select the control, not to be able to click the control, probably only disabling it:

txtMeuControle.Enabled = false;

This replaced the TabStop on desired functionality.

  • The . Enabled solved exactly the two things the "click" and the "TAB" he jumps. Certinho, thanks!!

Browser other questions tagged

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