set the Tab Key in Infragistics UltraTabWorkspace
September 18, 2009 Leave a Comment
In the Infragistics.Practices.CompositeUI.WinForms.UltraTabWorkspace workspace.
one of the projects i worked on we needed to have the Tab item key property set with a unique key, unfortunately the key property is not set when the tab is created(actually it was never set and always resolved to be null).
first of all create a custom SmartPartInfo that will hold an extra property TabKey.
public class CustomTabSmartPartInfo : Infragistics.Practices.CompositeUI.WinForms.UltraTabSmartPartInfo
{
private string _TabKey;
public string TabKey
{
get { return _TabKey; }
set { _TabKey = value; }
}
}
next inherit from the UltraTabWorkspace control and override two methods that will help set the key “manually”.
/// <summary>
/// inherited UltraTabWorkspace object in order to get access to the override methods
/// </summary>
/// <remarks>the reason is to set the TabKey property when the a workItem is created</remarks>
public class CustomUltraTabWorkspace : Infragistics.Practices.CompositeUI.WinForms.UltraTabWorkspace
{
private string addTabKey;
protected override void OnShow(System.Windows.Forms.Control smartPart, Infragistics.Practices.CompositeUI.WinForms.UltraTabSmartPartInfo smartPartInfo)
{
if ((smartPartInfo) is CustomTabSmartPartInfo)
{
if (Strings.Len(((CustomTabSmartPartInfo)smartPartInfo).TabKey) > 0)
{
addTabKey = ((CustomTabSmartPartInfo)smartPartInfo).TabKey;
}
}
base.OnShow(smartPart, smartPartInfo);
addTabKey = string.Empty;
}
protected override void OnControlAdded(System.Windows.Forms.ControlEventArgs e)
{
base.OnControlAdded(e);
if (Strings.Len(addTabKey) > 0)
{
if ((e.Control) is Infragistics.Win.UltraWinTabControl.UltraTabPageControl)
{
((Infragistics.Win.UltraWinTabControl.UltraTabPageControl)e.Control).Tab.Key = addTabKey;
}
}
}
}
when OnShow() is called for the first time OnControlAdded() will be called as well, this is the point to set the Tab Key which is extracted from the Custom smartPartInfo created earlier.
CustomTabSmartPartInfo spi = new CustomTabSmartPartInfo(); spi.Title = tabText; spi.TabKey = mSessionId + mName + ":" + viewId; ; spi.ActivateTab = activateTab; MyWorkspace.Show(thisView, spi);
All set the Tab’s Key property is populated and we have control over the content of the key, in my case it had to reflect the active session and the view id.