Home > C#, TFS > TFS SDK: WorkItemFormControl, a TFS control to view and edit a WorkItem

TFS SDK: WorkItemFormControl, a TFS control to view and edit a WorkItem

Go to the TFS Content Page


The TFS SDK come with a WinForm control named WorkItemFormControl that display the informations related to a WorkItem. The control allow edition.

The WorkItemFormControl is in the library Microsoft.TeamFoundation.WorkItemTracking.Controls.dll that is located under C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies.

You will need to add a reference to this library and a using on the namespace Microsoft.TeamFoundation.WorkItemTracking.Controls.

Note: You need to target the framework .NET Framework 4 not the .NET Framework 4 Client Profile. (Project properties, tab application)

Let’s create a Form named FormWorkItem:

using Microsoft.TeamFoundation.WorkItemTracking.Client;

public partial class FormWorkItem : Form
{
 public FormWorkItem(WorkItem workItem)
 {
 InitializeComponent();
 }
}

Add the namespace for the control:

using Microsoft.TeamFoundation.WorkItemTracking.Controls;

Create and bind the WorkItemFormControl:

using Microsoft.TeamFoundation.WorkItemTracking.Controls;

public partial class FormWorkItem : Form
{
 private WorkItem workItem;

 public FormWorkItem(WorkItem workItem)
 {
 this.workItem = workItem;

 InitializeComponent();

 WorkItemFormControl control = new WorkItemFormControl();
 control.Item = workItem;
 control.ReadOnly = false;
 control.Dock = DockStyle.Fill;
 this.Controls.Add(control);

 this.Text = workItem.Type.Name + ": " + workItem.Id + " - " + workItem.Title;
 }
}

Let’s add a FormClosing event to save the WorkItem:

if (this.workItem.IsDirty)
{
 DialogResult result = MessageBox.Show("Do you want to save changes?", "Save", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
 if (result == System.Windows.Forms.DialogResult.Yes)
 {
 try
 {
 this.workItem.Save();
 }
 catch (Exception ex)
 {
 MessageBox.Show(ex.Message);
 }
 }
 else if (result == System.Windows.Forms.DialogResult.No)
 this.workItem.Reset();
 else
 e.Cancel = true;
}
Categories: C#, TFS
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: