Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm Data Binding / October 2004

Tip: Looking for answers? Try searching our database.

datagrid databinding puzzles

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
cnSoftware - 09 Oct 2004 04:15 GMT
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.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.