This is a migrated thread and some comments may be shown as answers.

How do I programatically select a tab in RichTextEditorRibbonBar?

1 Answer 169 Views
RichTextEditor
This is a migrated thread and some comments may be shown as answers.
Pavel
Top achievements
Rank 1
Pavel asked on 27 Dec 2016, 08:35 PM

I am adding a new tab to the RichTextEditorRibbonBar like this:

var lblTempalteName = new RadLabelElement() {
    Text = "Template Name:",
    AutoSize = false,
    Size = new Size(120, 20)};
var tbxTemplateName = new RadTextBoxElement() {
    Size = new Size(100, 25),
    Padding = new Padding(2) };
var templateNameGroup = new RadRibbonBarButtonGroup();
templateNameGroup.Items.AddRange(new RadItem[] { lblTempalteName, tbxTemplateName });
 
var lblDataSource = new RadLabelElement() {
    Text = "Data Source:",
    AutoSize = false,
    Size = new Size(120, 20)};
var ddlDataSource = new RadDropDownListElement() {
    Size = new Size(100, 25),
    DropDownStyle = RadDropDownStyle.DropDownList };
var dataSourceGroup = new RadRibbonBarButtonGroup() { Margin = new Padding(0, 3, 0, 0) };
dataSourceGroup.Items.AddRange(new RadItem[] { lblDataSource, ddlDataSource });
 
var rbgProperties = new RadRibbonBarGroup()
{
    Text = "Properties",
    Orientation = Orientation.Vertical
};
rbgProperties.Items.AddRange(new RadItem[] { templateNameGroup, dataSourceGroup });
 
 
var templatePropertiesTab = new RichTextEditorRibbonTab() { Text = "Template properties", IsSelected = false};
templatePropertiesTab.Items.Add(rbgProperties);
 
richTextEditorRibbonBar1.CommandTabs.Add(templatePropertiesTab);

The tab that I am adding becomes selected, which isn't what I want. How do I ensure that the "Home" tab is selected. Here's what I tried, but it doesn't work.

foreach (RibbonTab item in richTextEditorRibbonBar1.CommandTabs)
{
    item.IsSelected = (item.AccessibleName == "Home");
}
richTextEditorRibbonBar1.Refresh();

1 Answer, 1 is accepted

Sort by
0
Accepted
Lance | Manager Technical Support
Telerik team
answered on 27 Dec 2016, 09:23 PM
Hello Pavel,

You don't need to iterate over the tab collection to get the Home tab, here's another approach using index:

var homeTab = richTextEditorRibbonBar1.CommandTabs[0] as RichTextEditorRibbonTab;
 
if (homeTab != null)
    homeTab.IsSelected = true;

That will select the home tab, I've attached a small runnable demo for you to see it working. 


If using the index can't work for you and you have to iterate over the CommandTabs collection, I recommend using a foreach with a var and then do a safe cast inside the loop, like this:

foreach (var commandTab in richTextEditorRibbonBar1.CommandTabs)
{
    var tab = commandTab as RichTextEditorRibbonTab;
 
    if (tab?.AccessibleName == "Home")
    {
        tab.IsSelected = true;
    }
}

Let us know if you have any further questions. Thank you for contacting Support and for choosing Telerik by Progress.

Regards,
Lance | Tech Support Engineer, Sr.
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
RichTextEditor
Asked by
Pavel
Top achievements
Rank 1
Answers by
Lance | Manager Technical Support
Telerik team
Share this question
or