I'm having a question regarding the Set
and Get
property. I am using them to validate textbox
, which are empty. However, after the value is entered and saved in the database, the value is stored in the variable, causing it to bring the previous value in the other register.
public class MyRecord : IDXDataErrorInfo
{
private string firstName;
private string password;
private string password_rev;
private string nome;
private string sobrenome;
public MyRecord()
{
}
public string FirstName
{
get { return firstName; }
set { firstName = value; }
}
public string Password
{
get { return password; }
set { password = value; }
}
public string Password_rev
{
get { return password_rev; }
set { password_rev = value; }
}
public string Nome
{
get { return nome; }
set { nome = value; }
}
public string Sobrenome
{
get { return sobrenome; }
set { sobrenome = value; }
}
// Implements the IDXDataErrorInfo.GetPropertyError method.
public void GetPropertyError(string propertyName, ErrorInfo info)
{
if (propertyName == "FirstName" && FirstName == "" || propertyName == "Password" && Password == "" || propertyName == "Password_rev" && Password_rev == "" || propertyName == "Nome" && Nome == "" || propertyName == "Sobrenome" && Sobrenome == "")
{
info.ErrorText = String.Format("O campo não pode estar em branco", propertyName);
}
}
// IDXDataErrorInfo.GetError method
public void GetError(ErrorInfo info) { }
}//componente do dxerrorprovider
Here's the code I'm using to pass the values:
if (bindingSource1.Count != 0)
{
controles_text control_text = new controles_text();
control_text.bdclear(this.Controls);
}
// especifica o tipo de bind
bindingSource1.DataSource = typeof(MyRecord);
// cria myrecord com o valor dos textbox e add ao bind
MyRecord rec = new MyRecord();
rec.FirstName = textEdit1.Text;
rec.Password = textEdit6.Text;
rec.Password_rev = textEdit5.Text;
rec.Nome = textEdit7.Text;
rec.Sobrenome = textEdit8.Text;
bindingSource1.Add(rec);
// bind do textbox ao myrecord
textEdit1.DataBindings.Add(new Binding("EditValue", this.bindingSource1, "FirstName", true));
textEdit6.DataBindings.Add(new Binding("EditValue", this.bindingSource1, "Password", true));
textEdit5.DataBindings.Add(new Binding("EditValue", this.bindingSource1, "Password_rev", true));
textEdit7.DataBindings.Add(new Binding("EditValue", this.bindingSource1, "Nome", true));
textEdit8.DataBindings.Add(new Binding("EditValue", this.bindingSource1, "Sobrenome", true));
// Bind the DXErrorProvider to the data source.
dxErrorProvider1.DataSource = bindingSource1;
// Specify the container of controls (textEdit1 and textEdit2)
// which are monitored for errors.
dxErrorProvider1.ContainerControl = this;
if (textEdit1.Text != string.Empty && textEdit6.Text != string.Empty && textEdit5.Text != string.Empty && textEdit7.Text != string.Empty && textEdit8.Text != string.Empty)
{
// Inicia minhas validações de dados
}