3

I would like to extend the team explorer work item editor with a custom functional button along side export to excel, outlook etc, taking information from the current work item.

I know there is a way to modify the items themselves, as described at witcustomcontrols.codeplex.com, but I'd rather not modify them.

Is the editor extensible in this way, or are there better ways to do this?

Best Regards, Tommy

lobotommy
  • 91
  • 6

1 Answers1

4

Creating a Work Item Custom Control is the way to accomplish what you're trying to do.

The project you already found (witcustomcontrols.codeplex.com) is a good starting point to understand the mechanics of creating work item custom controls, so I'll limit myself to describing the specifics of implementing the basics of a Custom Button.

Create a control that derives from System.Windows.Button and access the WorkItemDatasource property from the OnClick method.

This should get you started:

using System;
using System.Collections.Specialized;
using System.Windows.Forms;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Controls;

namespace Wicc {
    public class ButtonControl: Button, IWorkItemControl {
        public ButtonControl() {

        }
        protected override void OnClick(EventArgs e) {
            WorkItem workItem = this.WorkItemDatasource as WorkItem;

            // the rest of your code
        }

        #region IWorkItemControl Members

        public event EventHandler AfterUpdateDatasource;

        public event EventHandler BeforeUpdateDatasource;

        public void Clear() {
        }

        public void FlushToDatasource() {
        }

        public void InvalidateDatasource() {
        }

        public StringDictionary Properties {get; set;}

        public bool ReadOnly {get; set;}

        public void SetSite(IServiceProvider serviceProvider) {
        }

        public object WorkItemDatasource { get; set; }

        public string WorkItemFieldName { get; set; }

        #endregion
    }
}

In case you have further questions, let me know.

Alfred Myers
  • 6,384
  • 1
  • 40
  • 68
  • Thank you, this seems like a good approach. Have found ways to extend the query result windows (based on [this](http://blogs.msdn.com/b/team_foundation/archive/2010/06/24/extending-work-item-tracking-context-menus.aspx) and [this](http://social.msdn.microsoft.com/Forums/en/vsx/thread/f87af77f-d431-4246-9631-de92c6533bfb)), but your approach is smoother. – lobotommy Jun 29 '12 at 07:44
  • Implemented it now, works like a charm. Unfortunately my reputation is not good enough to up the score, but thanks a lot for the help. – lobotommy Jun 29 '12 at 11:19
  • I'm not sure I understand what you mean by "my reputation is not good enough to up the score". You can vote on an answer clicking the up or down buttons next to the score and you can accept an answer marking the tick sign below the score. – Alfred Myers Jun 29 '12 at 12:01
  • @alfred, people with rep less than 40 (IIRC) can't vote up/down, but they can mark as answer. you can vote up his question for him to get 5 extra rep point. I voted up both of you! ;) – Nock Jun 29 '12 at 13:24