Microsoft Knowledge Base Article
This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved.
Terms
of Use |
Trademarks
Article ID: 952657 - Last Review: May 2, 2008 - Revision: 1.0
Windows Forms 2.0 Currency Manager moves to wrong position after adding a new item with AddNew() and EndCurrentEdit()
Source: Microsoft Support
RAPID PUBLISHING
RAPID PUBLISHING ARTICLES PROVIDE INFORMATION DIRECTLY FROM WITHIN THE MICROSOFT SUPPORT ORGANIZATION. THE INFORMATION CONTAINED HEREIN IS CREATED IN RESPONSE TO EMERGING OR UNIQUE TOPICS, OR IS INTENDED SUPPLEMENT OTHER KNOWLEDGE BASE INFORMATION.
Action
You have a Windows Form on a machine with Microsoft .NET Framework 2.0 Service Pack 1 installed. You create a System.Data.DataView object and assign a System.Data.DataTable object to it in the form. You populate the DataTable object and call Sort() on the DataView object. Now, you get the Currency Manager object from the form through BindingContext[the DataView object].
You call AddNew() on the Currency Manager object, get the DateRowView object from Current property on the Currency Manager object, and set up the DataRowView object with the data so that it will be sorted to somewhere in the middle in the DataView object.
You call EndCurrentEdit() on the Currency Manager object to finish adding the item.
Result
When you call Current Property on the Currency Manager object, it will not return the item you added, but the item below it.
Resolution
You need to keep the reference to the new item from Current property on the Currency Manager object after calling AddNew(). After calling EditCurrentEdit() on the Currency Manager object, call Current on the Currency Manager and check if it is the same as the reference you kept.
If they are different, you can set Position on the Currency Manager to the one below it. You need to make sure there is an item below it. You can also find the index of the new item through calling List.IndexOf(the new Item) and set Position on the Currency Manager to the index.
You should do the comparison check before fixing Position to avoid doing this when this issue is addressed in the future release of .NET Framework or on the machine without .NET Framework 2.0 SP1.
Â
DISCLAIMER
MICROSOFT AND/OR ITS SUPPLIERS MAKE NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY, RELIABILITY OR ACCURACY OF THE INFORMATION CONTAINED IN THE DOCUMENTS AND RELATED GRAPHICS PUBLISHED ON THIS WEBSITE (THE “MATERIALSâ€) FOR ANY PURPOSE. THE MATERIALS MAY INCLUDE TECHNICAL INACCURACIES OR TYPOGRAPHICAL ERRORS AND MAY BE REVISED AT ANY TIME WITHOUT NOTICE.
TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, MICROSOFT AND/OR ITS SUPPLIERS DISCLAIM AND EXCLUDE ALL REPRESENTATIONS, WARRANTIES, AND CONDITIONS WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT LIMITED TO REPRESENTATIONS, WARRANTIES, OR CONDITIONS OF TITLE, NON INFRINGEMENT, SATISFACTORY CONDITION OR QUALITY, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, WITH RESPECT TO THE MATERIALS.
APPLIES TO
- Microsoft .NET Framework 2.0 Service Pack 1 (x86)
- Microsoft .NET Framework 3.0
- Microsoft .NET Framework 3.5
| kbnomt kbrapidpub KB952657 |
Community Feedback System
Very often, it takes hours to solve a problem. Very often, you've looked high
and low, and have tried a lot of solutions. When you finally found it, chances
are, it was because someone else helped you. Here's your chance to give back.
Use our community feedback tool to let others know what worked for you and what
didn't.
Please also understand that the community feedback system is not warranted to be
correct, it's simply a system that we've built to let people try and help each
other. If something in a feedback response doesn't make sense to you, or you're
not comfortable making changes that the feedback talks about (like registry
edits), please consult a professional.
Thank you for using kbAlertz.com Feedback System.
-- Scott Cate
Be the first to leave feedback, to help others about this knowledge base
article.
(Optional) Name
(Optional)
Public URL Or Email
Comments
No
HTML -- Text Only Please