When setting SelectedTabIndex having 4 tabs, all of the visible, everything works normally:
Ribbon.SelectedTabIndex = Ribbon.Tabs.IndexOf(Ribbon
.FindTabByValue("tabName"))
However when I make some tabs invisible (index 0 and 2 in my case), it completely messes up the SelectedTabIndex property:
It defaults to 1, and it seems to be impossible to change. Even having this value it is still inconsistent, showing either tab 1 or 3:
When tab 1 is selected client side and a postback occurs, the selected tab will switch to 3 on the client side after postback and vice versa.
To make the tabs invisible I use:
Menu.Tabs(0).Visible = False
Menu.Tabs(2).Visible = False
Am I making a mistake or is this really a bug?
Update: It works when programatically removing the tabs before setting the index. This works for me as I won't need the invisible tabs on the client side or serverside anyway, but I imagine this might cause problems for other people.
7 Answers, 1 is accepted
Unfortunately I wasn't able to reproduce this issue. Perhaps I am missing something. Could you please specify the exact sequence of actions that leads to the problem. A video capture of it would also be very helpful.
All the best,
Bozhidar
the Telerik team
Example:
There are 7 visible tabs (indexes 0-6) and fifth tab was selected as active (RadRibbonBar.SelectedTabIndex = 4). Make second tab invisible now (index 1) and RadRibbonBar.SelectedTabIndex now equals 5 which points to a different tab being selected than one desired.
It seems RadRibbonBar.SelectedTabIndex property is maintained only for visible members of collection although oddly the tab count does not increase/decrease.
I'm somewhat at odds with the original post as making the tabs invisible before setting the index screws things up anyway (using said C# code behind approach).
-----------------------------------------------------------------------
Code sample:
private void DirectoryTabSetUp()
{
if (ClientsModules.HasFlag(ClientsModuleTypes.DirectoryAccess))
{
if (CurrentUserSettings.ContainsKey(UserSettingTypes.DirectoryAccessOnly))
{
ribTabDrawings.Visible = true;//albeit this will be simplified version of Drawings
ribTabFiles.Visible = false;
ribTabAdmin.Visible = false;
rbTabReporting.Visible = false;
ribTabExplore.Visible = false;
RadRibbonBar.SelectedTabIndex = 4;
SimpleDrawingTabSetUp();
}
}
else
{
ribTabDirectory.Visible = false;
}
}
------------------------------------------------------------------------
For the above sample, all that matters is that ribTabDrawings has a tab index of 0 in collection and ribTabDirectory has tab index of 4. When one sets RadRibbonBar.SelectedTabIndex = 4 in the code above, SelectedTabIndex is coalesced to 0 making ribTabDrawings tab active. If I now wanted to make ribTabDirectory selected I'd need to code RadRibbonBar.SelectedTabIndex = 1 (effectively saying, hey there are now only 2 visible tabs, make the second one active). But that's just visual order (from left to right to boot).
Thanks,
Ned
Thank you for clarifying.
I confirm that this is a bug in the RibbonBar and I have logged it for fixing in our system.
All the best,
Bozhidar
the Telerik team
Thanks,
Bharath
Since this thread is more than a year old, could you provide the code for your current implementation and steps to reproduce, as well as the desired and actual results you are getting?
Regards,
Bozhidar
Telerik
Let me know if you need anything else.
private int RibbonBarSelectedTab
{
set { Session["RibbonBarSelectedTab"] = value; }
get { return (Session["RibbonBarSelectedTab"] != null) ? (int)Session["RibbonBarSelectedTab"] : 0; }
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
// Here the SelectedTabIndex is showing as 1 if I have the first Tab set to invisible. If that is visible, then index shows as 0;
this.MasterRadRibbonBar.SelectedTabIndex = this.RibbonBarSelectedTab;
}
}
protected void MasterRadRibbonBar_ButtonClick(object sender, Telerik.Web.UI.RibbonBarButtonClickEventArgs e)
{
this.RibbonBarSelectedTab =e.Group.Tab.TabIndex;
if(!string.IsNullOrEmpty(e.Button.CommandName.Trim())) { Response.Redirect(e.Button.CommandName.Trim()); }
}
protected void MasterRadRibbonBar_SplitButtonClick(object sender, RibbonBarSplitButtonClickEventArgs e)
{
this.RibbonBarSelectedTab = e.Group.Tab.TabIndex;
if (!string.IsNullOrEmpty(e.Button.CommandName.Trim())) { Response.Redirect(e.Button.CommandName.Trim()); }
}
<telerik:RadRibbonBar ID="MasterRadRibbonBar" runat="server" Width="100%" OnButtonClick="MasterRadRibbonBar_ButtonClick" OnSplitButtonClick="MasterRadRibbonBar_SplitButtonClick" >
<Tabs>
<telerik:RibbonBarTab Text="Accounting" Value="Accounting" TabIndex="0">
<telerik:RibbonBarGroup Text="Freight" EnableLauncher="false">
<Items>
<telerik:RibbonBarButton Size="Medium" Text="Reconciliation" ImageUrl="../Images/16X16/Reconciliation.PNG" CommandName="~/Application/Accounting/ReconciliationFreight.aspx" />
</Items>
</telerik:RibbonBarGroup>
</telerik:RibbonBarTab>
<telerik:RibbonBarTab Text="CIP" Value="CIP" TabIndex="1">
<telerik:RibbonBarGroup Text="Improvements" EnableLauncher="false">
<Items>
<telerik:RibbonBarButton Size="Medium" Text="Action Request" ImageUrl="../Images/16X16/ActionRequest.png" CommandName="~/Application/CIP/ActionRequest.aspx" />
<telerik:RibbonBarButton Size="Medium" Text="CICAR" ImageUrl="../Images/16X16/CICAR.png" CommandName="~/Application/CIP/Cicar.aspx" />
</Items>
</telerik:RibbonBarGroup>
</telerik:RibbonBarTab>
</Tabs>
</telerik:RadRibbonBar>
Thank you for the provided code.
The behavior you are observing is the expected one. Let me elaborate: when you set the first tab to be invisible, it cannot be selected. Therefore the ribbonbar selects the next visible tab (in your case the second one). That's why the index is showing as 1. If it were the other way around, and you only count the index of the visible tabs, then upon showing/hiding of tabs the selected index will suddenly point to a different tab, which might cause errors.
Regards,
Bozhidar
Telerik