Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Microsoft.TeamFoundation.WorkItemTracking.Client;
- using Microsoft.TeamFoundation.WorkItemTracking.Controls;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace MyTFSCustomFields
- {
- public class TFSCombo: ComboBox, IWorkItemControl
- {
- public TFSCombo()
- {
- this.SelectedValueChanged += TFSCombo_SelectedValueChanged;
- // Simulation de la récupération des éléments :
- this.Items.Clear();
- this.Items.AddRange(new string[] { "1", "2", "3" });
- }
- void TFSCombo_SelectedValueChanged(object sender, EventArgs e)
- {
- // On enregistre dès la modification.
- this.FlushToDatasource();
- }
- #region Implementation Interface
- // Propriétés
- public event EventHandler AfterUpdateDatasource;
- public event EventHandler BeforeUpdateDatasource;
- public bool ReadOnly { get; set; }
- public object WorkItemDatasource { get; set; }
- public string WorkItemFieldName { get; set; }
- public System.Collections.Specialized.StringDictionary Properties { get; set; }
- // Méthodes
- public void Clear()
- {
- this.SelectedIndex = -1;
- }
- public void FlushToDatasource()
- {
- // Sauvegarde de la valeur vers le WI.
- if ((this.WorkItemDatasource as WorkItem) == null || (this.WorkItemDatasource as WorkItem).Fields[this.WorkItemFieldName] == null)
- {
- // this.Items.Add(string.Format("Either WI is null : '{0}'", this.WorkItemDatasource as WorkItem));
- return;
- }
- (WorkItemDatasource as WorkItem).Fields[WorkItemFieldName].Value = this.SelectedItem;
- // this.Items.Add(string.Format("WI has been changed with value : {0} / {1} / {2} / {3}", this.SelectedText, this.SelectedIndex, this.SelectedItem, this.SelectedValue));
- }
- public void InvalidateDatasource()
- {
- // Réinitialise le champ à la valeur stockée sur le WI.
- if ((this.WorkItemDatasource as WorkItem) == null || (this.WorkItemDatasource as WorkItem).Fields[this.WorkItemFieldName] == null
- || (this.WorkItemDatasource as WorkItem).Fields[this.WorkItemFieldName].Value == null)
- {
- return;
- }
- base.SelectedItem = (this.WorkItemDatasource as WorkItem).Fields[this.WorkItemFieldName].Value;
- }
- public void SetSite(IServiceProvider serviceProvider)
- {
- serviceProvider.GetService(typeof(IWorkItemControlHost));
- }
- #endregion
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement