MSMVPS.COM
The Ultimate Destination for Blogs by Current and Former Microsoft Most Valuable Professionals.

VSTO 2003 - How to detect cell edit is still in process

I've been doing a bit of VSTO work supporting a client that Linda (my wife) was working with before beginning her maternity leave (new bub due later this week), and have come across an interesting problem where a custom command button is still active when a user is editing a cell. If the user clicks the button, the edit is not committed, and when the value of the cell is read from code, the old value is returned. There is no programmatic way to commit the edit. For the particular application I'm looking after, the particular Excel workbook in a data entry application (chosen to maintain the end-clients existing workflow) that uploads the data to a server, so the issue with the uncommitted cell is pretty important.

A look at the newsgroups shows that this is one of the problems that doesn't have a clean solution. The best direct solution is to simulate the Enter key with a SendKeys, which is pretty fragile solution. I've found that the Recalaculate method of the Workbook throws an exception if it is called while a cell edit is in progress, so we can at least detect if the data is in a dodgey state before it is upload. As a secondary precaution, we're going to add an optional data summary message box or form to detail the exact data that is going to uploaded to the server so the user has a final chance to eye-ball it before it goes.

For historical reasons this is a VSTO 2003 project - I'll be interested to see if this problem is fixed in VSTO 2005.
Posted Sep 25 2006, 07:58 AM by nick
Filed under:

Comments

bill wrote re: VSTO 2003 - How to detect cell edit is still in process
on 09-25-2006 2:29

what happens if you change the active cell and then back ?  Assuming that works, I think that would be preferable to sending "enter" which could trigger who knows what ;)

nick wrote re: VSTO 2003 - How to detect cell edit is still in process
on 09-25-2006 2:38

Setting the ActiveCell is ignored if you're in the middle of an edit.  Tried that one :)

bill wrote re: VSTO 2003 - How to detect cell edit is still in process
on 09-25-2006 2:52

:S that sucks.   Well I would at least make it sendkeys TAB, as that will have less likelihood of side effects (but not by much <g>)

bill wrote re: VSTO 2003 - How to detect cell edit is still in process
on 09-25-2006 2:53

oops, was my comment blocked cause I said sucks ?

bill wrote re: VSTO 2003 - How to detect cell edit is still in process
on 09-25-2006 2:53

nope there it is ;)



Copyright © is the original authors. Blog site is an independent site not sponsored by Microsoft. The Yoda blog server and the Brianna SQL server would like to thank www.ownwebnow.com and www.exchangedefender.com. They wouldn't be here and broadcasting without the generosity of Vlad Mazek and his companies.

Powered by Community Server (Commercial Edition), by Telligent Systems