Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
200
TabGroupPane - UNABLE TO SET SELECTED TAB!!!`1
posted

Very simple piece of code. Why is it not working? Super frustrated, I've spent half a day battling this plus additional xamDataGrid nonsense (autogenerated fields ignoring format specifier in my custom EditorStyle). Here's the code where I specifically tell the tab control to set the selected item, and the infragistics control decides to IGNORE what I tell it. Can someone explain what's happening?

private void SetDocumentHostContent(DocumentContentHost host, object viewToAdd)
{
var rootDocumentPane = host.Panes.First();
var tabGroupPane = rootDocumentPane.Panes.OfType<TabGroupPane>().First();

var tradeItem = tabGroupPane.Items.OfType<ContentPane>().FirstOrDefault(p => (p.Header ?? "").ToString() == "Trades");
var cashReportItem = tabGroupPane.Items.OfType<ContentPane>().FirstOrDefault(p => (p.Header ?? "").ToString() == "Cashflow Report");
var notionalReportItem = tabGroupPane.Items.OfType<ContentPane>().FirstOrDefault(p => (p.Header ?? "").ToString() == "Reset Notional Report");
var importItem = tabGroupPane.Items.OfType<ContentPane>().FirstOrDefault(p => (p.Header ?? "").ToString() == "CSV");

var removeItems = new[] { tradeItem, cashReportItem, notionalReportItem, importItem }.Where(r => r != null).ToList();

ContentPane firstItem = null;
var headerToUse = string.Empty;
switch (viewToAdd.GetType().Name)
{
case "SearchResultsView":
headerToUse = "Trades";
firstItem = tradeItem;
break;
case "CashflowReportView":
headerToUse = "Cashflow Report";
firstItem = cashReportItem;
break;
case "ResetNotionalReportView":
headerToUse = "Reset Notional Report";
firstItem = notionalReportItem;
break;
case "ImportedResultView":
headerToUse = "CSV";
firstItem = importItem;
break;
}

if (firstItem != null)
{
// reports & trade query tabs need to be preserved - delist them from the remove list
// imports tab needs to be removed, so keep that one on the remove list
if (!firstItem.Equals(importItem))
{
removeItems.Remove(firstItem);
firstItem = null;
}
}

var restoreSet = tabGroupPane.Items.OfType<ContentPane>().Where(p => !removeItems.Contains(p)).ToList();

var itemsToClear = tabGroupPane.Items.OfType<ContentPane>().ToList();
foreach (var content in itemsToClear)
{
tabGroupPane.Items.Remove(content);
}

if (firstItem == null)
{
// create the new view here and add as a tab
firstItem = new ContentPane
{
AllowClose = true,
AllowDockingFloating = false,
AllowFloatingOnly = false,
AllowDocking = false,
AllowInDocumentHost = true,
AllowDockingInTabGroup = false,
CloseButtonVisibility = Visibility.Visible,
PinButtonVisibility = Visibility.Collapsed,
WindowPositionMenuVisibility = Visibility.Collapsed,
Content = viewToAdd,
Header = headerToUse
};

restoreSet.Insert(0, firstItem);
}
else
{
firstItem.Content = viewToAdd;
}

foreach (var contentPane in restoreSet)
{
tabGroupPane.Items.Add(contentPane);
}
tabGroupPane.SelectedItem = firstItem;
}