Team Foundation Server: Alert changes in custom control.
Well TFS is not my specialty, but some time ago I was asked to develop custom control for one of our clients… This process is very easy and intuitive, so it did not took ages, as I thought in the beginning…
But I’ve encountered small but very annoying(in UI aspect) problem. After implementing all the needed (IWorkItemControl interface etc.) and placing my custom control into standard work item, I’ve discovered that opened work item does not indicates that any change was made if changes are made in my custom control. This means that if a user will not push save button in Visual Studio IDE data that was changed in my custom control will be lost.
After a wile I’ve found a very simple solution:
Two properties that have to be implemented in IWorkItemControl interface:
1. WorkItemDatasource – holds a reference to a work item and should be casted to a WorkItem class.
2. WorkItemFieldName – holds a name of a field that defined in work item’s XML definition.
This row is the solution:
(WorkItemDatasource as WorkItem).Fields[WorkItemFieldName].Value = someValue;
Apparently updating “Value” property , not only changes the value, but also indicates to a work item that some changes were made. Now if user will try to close a work item without saving - Visual Studio IDE will alert him on attempt to close work item with unsaved data in it.
Enjoy and feel free to contact me if you have any questions.