Tomasz J
9/20/2007 11:43:00 AM
Hello WenYuan,
I am sorry, I missed something. Please scratch out the previous post.
Here are the steps to reproduce the problem:
1. in the following order add new BindingSource to a new form,
2. add new BindingNavigator,
3. add new DataGridView,
4. add new TextBox,
5. set dataGridView1.DataSource to bindingSource1
6. set bindingNavigator1.BindingSource to bindingSource1
7. paste this code into form constructor:
DataTable dt = new DataTable();
dt.Columns.Add("test", typeof(string));
bindingSource1.DataSource = dt;
dataGridView1.AllowUserToAddRows = false;
dataGridView1.AllowUserToDeleteRows = false;
dataGridView1.AutoGenerateColumns = true;
textBox1.DataBindings.Add(new Binding("Text", bindingSource1, "test",
true));
8. Create bindingSource1 PositionChanged event handler and paste the
following code:
if (bindingSource1.Current == null) {
//dataGridView1.TabStop = false;
textBox1.Enabled = false;
} else {
//dataGridView1.TabStop = true;
textBox1.Enabled = true;
if (((DataRowView)bindingSource1.Current).IsNew) {
textBox1.Focus();
}
}
See what happens when you add and remove the first record using binding
navigator.
Commented out lines seem to remedy the problem - the best solution I found
so far.
Thank you,
Tomasz J