Jaa


Showing work item form in your app

I hear this question often: How to show work item form in an app? Either an existing workitem, or a new workitem, possibly with certain fields prefilled? This is done as part of samples in SDK, but it is worth a post. It is quite easy and below is the code to do it:

 

    using Microsoft.TeamFoundation.WorkItemTracking.Controls;

    static void ShowWorkItem(WorkItem wi)

    {

        WorkItemFormControl formControl = new WorkItemFormControl();

        formControl.Item = wi;

        formControl.ReadOnly = false;

        formControl.Dock = DockStyle.Fill;

        Form form = new Form();

        form.Text = String.Format("Work item {0}", wi.Id);

        form.Size = formControl.Size;

        form.Controls.Add(formControl);

        form.Show();

    }

 

The WorkItem object passed can be a "new WorkItem()" or existing one. This needs reference to Microsoft.TeamFoundation.WorkItemTracking.Controls.dll, which can be found under devdiv installation folder, usually <drive>:\Program Files\Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies.

 

Now the work item form is shown, how to save the changes, show “dirtiness” and validate changes? These can be done directly to WorkItem object. WorkItem.Save() can be called to save it. Use WorkItem.IsDirty to track if user made any changes, and validate its fields using WorkItem.Fields[<index here>].IsValid call.

 

Other controls like result list can also be hosted in other application. To know how, check out WIBrowser sample in VSSDK (https://msdn.microsoft.com/vstudio/extend)

Comments

  • Anonymous
    January 22, 2007
    I have a problem with the code example described here: after form.Show an empty form without any controls is displayed. Busy-type mouse cursor is displayed when mouse is over the form. Am I missing something? Naren: I could not repro your problem - it works fine for me. It is hard to discuss issues in comments, so please raise this question in our forums if you still have trouble.

  • Anonymous
    January 07, 2015
    Muy tarde el comentario,,, pero muchas grascias me sirvio muchisimo