0
I have a form for client registration and within this form there is a RadioButton
that asks if this customer needs to send invoices, if the answer equal to SIM arise two components, a TextBox
and a DateTimePicker
.
if (rdsim.Checked == true)
{
metroPanel1.Controls.AddRange(new Control[]
{
new MetroFramework.Controls.MetroTextBox
{
Name = "txtconta", //aqui adiciono o nome do componente
Location = new Point(TextBoxX, 15),
Size = new Size(185, 30)
},
new MetroFramework.Controls.MetroDateTime
{
Name = "dtpvencimento", //aqui adiciono o nome do componente
Format = DateTimePickerFormat.Custom,
Location = new Point(DateTimeX, 13),
Size = new Size(124,33)
},
});
}
Thus, when the user clicks on the Register button I must pass this data to the database, I am doing so:
Contas contas = new Contas();
contas.Nroconta = txtconta.Text;
contas.Vencimento = dtpvencimento.Text;
But it returns me the error that these Names do not exist in the current context, how can I fix this? There is another way to assign a component, other than by your Name
?
I understood that’s exactly what I needed, perfect answer. I suspected that just assigning the name in that way was not enough but did not know how to complement. I think creating at design time and changing the visibility will not be possible in my case as it may have more than one account per customer.
– Patrick Perdigão