Hi Jeronimo,
Thanks for your post.
Yes, in .Net2.0, we can cancel the databinding now. Whenever we move to
next record in BindingNavigator, it will first validate the original
binding value for the bound control. So the TextBox's Validating event will
fire for it.
We can store the original binding value in a private field, then compare
the new TextBox value with the original cached value to determine if the
content is modified. And do canceling for it. The code snippet demonstrate
this:
private void LoadData()
{
DataSet set = new DataSet();
DataTable dt = new DataTable();
set.Tables.Add(dt);
dt.Columns.Add("column1", typeof(string));
dt.Columns.Add("column2", typeof(string));
bindingSource1.DataSource = set;
bindingSource1.DataMember = dt.TableName;
textBox1.DataBindings.Add("Text", bindingSource1, "column1");
textBox2.DataBindings.Add("Text", bindingSource1, "column2");
this.textBox1.DataBindings[0].Parse += new
ConvertEventHandler(Form1_Parse);
this.textBox1.DataBindings[0].Format += new
ConvertEventHandler(Form1_Format);
// Set the DataSource to the DataSet, and the DataMember
// to state.
for (int i = 0; i < 5; i++)
{
DataRow dr = dt.NewRow();
dr["column1"] = i.ToString();
dr["column2"] = "item"+i.ToString();
dt.Rows.Add(dr);
}
}
private void Form1_Load(object sender, EventArgs e)
{
LoadData();
}
private string orig_val = string.Empty;
void Form1_Format(object sender, ConvertEventArgs e)
{
orig_val = e.Value.ToString();
}
void Form1_Parse(object sender, ConvertEventArgs e)
{
}
private void textBox1_Validating(object sender, CancelEventArgs e)
{
if (this.textBox1.Text!=orig_val)
{
MessageBox.Show("cancel modifying");
e.Cancel = true;
this.textBox1.Text = orig_val;
}
}
Hope this helps.
============================================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! -
www.microsoft.com/security This posting is provided "as is" with no warranties and confers no rights.