4
I have the following user control that is being used in a Form:
public partial class CampoTelefone : UserControl
{
private void maskedTextBoxTelefone_Validating(object sender, CancelEventArgs e)
{
//validações
}
}
After the user fills the user control in the Form I pass it to another class that performs other types of validations, the parameter container
is getting a GroupBox
:
private void valida(Control container)
{
foreach (Control c in container.Controls.Cast<Control>().OrderBy(c => c.TabIndex))
{
valida(c);
if (c is CampoTelefone && c.Tag.ToString() == "1")
{
/*outras validações*/
}
}
}
In this part if (c is CampoTelefone && c.Tag.ToString() == "1")
I need to access the properties of c
which in this case is my user control, but its properties are not accessible, even passing a new user control instance to the method that runs the foreach
. The properties I can access are only those I defined at the time of user control implementation.
In this part of the code using control TextBox
works properly:
foreach (Control c in container.Controls.Cast<Control>().OrderBy(c => c.TabIndex))
{
valida(c);
if (c is TextBox && c.Tag.ToString() == "1")
{
// faço mais validacoes
}
}
I excluded the part of the code from the checks for the sake of space of the question, and used the campoTelefone
to simplify.
What would be the solution to this problem?
The paragraph where you say
O problema é o seguinte...
got very confused. If you can [Edit] your question and explain better, I’m sure I can help you with that =).– Jéf Bueno
Okay, I’m gonna make this part better.
– Robss70
@jbueno, see if it’s clearer.
– Robss70
I think I got your problem, but I don’t understand what you mean by
As propriedades que consigo acessar são somente as que defini no momento da implementação do user control
. Give me an example of these properties.– Jéf Bueno
I meant control properties, example: Tag, Mask, Textalign, Locked, Tabstop.
– Robss70