Advertisement
PtiTom

TFS ComboBox

May 19th, 2015 (edited)
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.78 KB | None | 0 0
  1. using Microsoft.TeamFoundation.WorkItemTracking.Client;
  2. using Microsoft.TeamFoundation.WorkItemTracking.Controls;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows.Forms;
  9.  
  10. namespace MyTFSCustomFields
  11. {
  12.     public class TFSCombo: ComboBox, IWorkItemControl
  13.     {
  14.         public TFSCombo()
  15.         {
  16.             this.SelectedValueChanged += TFSCombo_SelectedValueChanged;
  17.  
  18.             // Simulation de la récupération des éléments :
  19.             this.Items.Clear();
  20.             this.Items.AddRange(new string[] { "1", "2", "3" });
  21.         }
  22.  
  23.         void TFSCombo_SelectedValueChanged(object sender, EventArgs e)
  24.         {
  25.             // On enregistre dès la modification.
  26.             this.FlushToDatasource();
  27.         }
  28.  
  29.         #region Implementation Interface
  30.         // Propriétés
  31.         public event EventHandler AfterUpdateDatasource;
  32.  
  33.         public event EventHandler BeforeUpdateDatasource;
  34.  
  35.         public bool ReadOnly { get; set; }
  36.  
  37.         public object WorkItemDatasource { get; set; }
  38.  
  39.         public string WorkItemFieldName { get; set; }
  40.  
  41.         public System.Collections.Specialized.StringDictionary Properties { get; set; }
  42.  
  43.         // Méthodes
  44.         public void Clear()
  45.         {
  46.             this.SelectedIndex = -1;
  47.         }
  48.  
  49.         public void FlushToDatasource()
  50.         {
  51.             // Sauvegarde de la valeur vers le WI.
  52.             if ((this.WorkItemDatasource as WorkItem) == null || (this.WorkItemDatasource as WorkItem).Fields[this.WorkItemFieldName] == null)
  53.             {
  54. //                this.Items.Add(string.Format("Either WI is null : '{0}'", this.WorkItemDatasource as WorkItem));
  55.                 return;
  56.             }
  57.  
  58.             (WorkItemDatasource as WorkItem).Fields[WorkItemFieldName].Value = this.SelectedItem;
  59. //            this.Items.Add(string.Format("WI has been changed with value : {0} / {1} / {2} / {3}", this.SelectedText, this.SelectedIndex, this.SelectedItem, this.SelectedValue));
  60.         }
  61.  
  62.         public void InvalidateDatasource()
  63.         {
  64.             // Réinitialise le champ à la valeur stockée sur le WI.
  65.             if ((this.WorkItemDatasource as WorkItem) == null || (this.WorkItemDatasource as WorkItem).Fields[this.WorkItemFieldName] == null
  66.                  || (this.WorkItemDatasource as WorkItem).Fields[this.WorkItemFieldName].Value == null)
  67.             {
  68.                 return;
  69.             }
  70.  
  71.             base.SelectedItem = (this.WorkItemDatasource as WorkItem).Fields[this.WorkItemFieldName].Value;
  72.         }
  73.  
  74.         public void SetSite(IServiceProvider serviceProvider)
  75.         {
  76.             serviceProvider.GetService(typeof(IWorkItemControlHost));
  77.         }
  78.         #endregion
  79.     }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement