locked
Rehosting the work item control? RRS feed

  • Question

  • We have a VS integration, but we also have a separate app that uses the Microsoft.TeamFoundation.WorkItemTracking namespaces.  From this app, we want the user to be able to enter a bug.  We were about to create a dialog on which the user could enter all the info, but I had heard there might be a way to host a control that would contain all the fields for us.  I just haven't had any luck web searching :-)
    Wednesday, August 18, 2010 2:51 PM

Answers

  • I see there is a WorkItemFormControl, which is what we need.

    However, I'm having some trouble displaying it.  On one site, I saw a recommendation to do the following.  But in this case the form came up blank.

          TeamFoundationServer tfsServer = TeamFoundationServerFactory.GetServer(Settings.Default.TfsServer);
          WorkItemStore workItemStore = (WorkItemStore)tfsServer.GetService(typeof(WorkItemStore));
          WorkItemType workItemType = workItemStore.Projects[Settings.Default.TfsProject].WorkItemTypes["Bug"];
          Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItem workItem = new Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItem(workItemType);
          XmlDocument xmlDocument = workItemType.Export(false);
          _workItemForm.Item = workItem;
          _workItemForm.Dock = DockStyle.Fill;
          _workItemForm.FormDefinition = xmlDocument.InnerXml;
    

    The following code did diplay a form, but all the field labels were missing (the user wouldn't know what each field was for).

          Microsoft.TeamFoundation.WorkItemTracking.Controls.WorkItemFormControl formControl = new Microsoft.TeamFoundation.WorkItemTracking.Controls.WorkItemFormControl();
    
          Microsoft.TeamFoundation.Client.TeamFoundationServer tfsServer = Microsoft.TeamFoundation.Client.TeamFoundationServerFactory.GetServer(Settings.Default.TfsServer);
          Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore workItemStore = (Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore)tfsServer.GetService(typeof(Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore));
          Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemType workItemType = workItemStore.Projects[Settings.Default.TfsProject].WorkItemTypes["Bug"];
    
          Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItem workItem = new Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItem(workItemType);
          formControl.Item = workItem;
          formControl.ReadOnly = false;
          formControl.Dock = DockStyle.Fill;
    
          Form form = new Form();
          form.Text = String.Format("Work item {0}", workItem.Id);
          form.Size = formControl.Size;
    
          form.Controls.Add(formControl);
    
          form.Show();
    
    
    • Marked as answer by ekename Wednesday, August 18, 2010 8:33 PM
    Wednesday, August 18, 2010 8:33 PM