well, what's the difference between BindingManagerBase and
CurrencyManager?Instead of
BindingManagerBase I have tried to use a currencymanager in my code, but the
result is still far from my expectation.
UI of my program like this:
---------------------
| btnQuery | btnAdd |
---------------------
| |
| textBox1 | textBox2|
|--------------------|
| datagrid1 | // I only want to use the datagrid1 to display
the records while
---------------------- // I will actually input the data in textBox1 and
textBox2.
step 1. I click btnQuery to fill the dataSet:
{
dataSet = GetAllRows();
dataTable = dataSet.Tables[0];
dataView = dataTable.DefaultView;
textBox1.DataBindings.Add("Text",dataView,"Field1"); //Field1 is key
field
textBox2.DataBindings.Add("Text",dataView,"Field2");
datagrid1.DataSource = dataView;
_CurrencyManager = (CurrencyManager)this.BindingContext[dataView];
}
step 2. I click btnAdd to append a new row:
{
this._CurrencyManager.EndCurrentEdit();
this._CurrencyManager.AddNew();
textBox1.Focus(); //get ready for me to input data
}
Now there are several strange situations puzzle me:
1. If I set focus in textBox1 or textBox2 before step 2, everything is ok, a
new
row is appended at the end of the datagrid1 and the focus is in textBox1.
But
If I set focus in datagrid1 and then continue step 2, a new row is still
appended,
but when the focus jumps from the datagrid1 to textBox1, a warning
messagebox
appears to show,"Field1 could not be null,do you want to correct it?".
why does
it appear before I input data?
2. Continue the previous operation. If I choose "Yes" to correct, the focus
is set
to the new row of datagrid1 again. But if I choose "No", I can input data
in textBox1
and then textBox2. However, the new row of datagrid1 remains null value
before the
focus is set to the datagrid1 again. Since the data in textBox1 and the
datagrid1 have
been bound together through currencymanager, I think the modification of
data in textBox1 should
be shown in datagrid1 synchronously. So I can't explain the
situation.Why?
3. Furthur more, as I indicated before, since I just use the datagrid to
display records,
I set its Readonly property to be true. But when I click any cell of the
datagrid1,I find
it will still invoke the DataGridTextBoxColumn.Edit method. Why??
these problems have puzzled me for a long time, and I really appreciate any
advice.
Thanks a lot.
Sijin Joseph - 12 Oct 2004 04:50 GMT
One thing you may want to keep in mind is that after databinding if the
textbox loses focus then it will try to commit the values back to the
datasoruce.
Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph
> well, what's the difference between BindingManagerBase and
> CurrencyManager?Instead of
[quoted text clipped - 67 lines]
> advice.
> Thanks a lot.