RadPageView - create multiline strip element with RadCommandBar
| Product Version | Product | Author | Last modified |
|---|---|---|---|
| Q2 2015 | RadPageView for WinForms | Dimitar Karamfilov | 15/1/2014 |
PROBLEM
This article will show how RadCommandBar can be used with combination with RadPageView to achieve multiline strips (pages), which will make the navigation easy when the page view has more pages. Also this will allow the user to benefit from both controls features and navigate between pages in a flexible way.

SOLUTION
We can start by creating a blank project where we can add a RadCommandBar (docked to the Top as is by default) and a RadPageView with a few pages:

Now we are ready to add the actual code, which will add buttons to the command bar. First we will create a CommandBarRowElement and CommandBarStripElement, we will use these elements to host and separate the buttons. Each row will contain a strip with maximum four buttons in it. New row will be created every time when the button number is greater than four. Then we will create, initialize and add a button to the corresponding command bar row for each page. Also we can hide the strip’s overflow button.
We can add a label to each page which will give us a visual clue that the current page is changed. Finally we can hide the original page view strip items:
public Form1()
{
InitializeComponent();
CommandBarRowElement row = new CommandBarRowElement();
CommandBarStripElement strip = new CommandBarStripElement();
row.Strips.Add(strip);
radCommandBar1.Rows.Add(row);
foreach (RadPageViewPage page in radPageView1.Pages)
{
if (strip.Items.Count >3)
{
row = new CommandBarRowElement();
strip = new CommandBarStripElement();
row.Strips.Add(strip);
radCommandBar1.Rows.Add(row);
}
CommandBarButton pageButton = new CommandBarButton();
pageButton.DrawText = true;
pageButton.Orientation = Orientation.Horizontal;
pageButton.Image = null;
pageButton.Text = page.Item.Text;
pageButton.Click += new EventHandler(pageButton_Click);
pageButton.StretchHorizontally = true;
strip.Items.Add(pageButton);
strip.StretchHorizontally = true;
strip.OverflowButton.Visibility = Telerik.WinControls.ElementVisibility.Collapsed;
//adding a label to each page in order to verify the change when a command bar button is clicked
RadLabel pageTitle = new RadLabel();
pageTitle.Text = "Current page = " + page.Item.Text;
pageTitle.Location = new Point(10, 10);
page.Controls.Add(pageTitle);
}
RadPageViewStripElement stripElement = radPageView1.ViewElement as RadPageViewStripElement;
stripElement.ItemContainer.Visibility = Telerik.WinControls.ElementVisibility.Collapsed;
}
void pageButton_Click(object sender, EventArgs e)
{
CommandBarButton pageButton = sender as CommandBarButton;
radPageView1.SelectedPage = radPageView1.Pages[pageButton.Text];
//reset all buttons colors
foreach (CommandBarRowElement row in radCommandBar1.Rows)
{
foreach (CommandBarStripElement strip in row.Strips)
{
foreach (CommandBarButton button in strip.Items)
{
button.ResetValue(LightVisualElement.BackColorProperty, Telerik.WinControls.ValueResetFlags.Local);
button.ResetValue(LightVisualElement.NumberOfColorsProperty, Telerik.WinControls.ValueResetFlags.Local);
}
}
}
pageButton.BackColor = Color.LightSalmon;
pageButton.NumberOfColors = 1;
}
The complete examples in C# and VB can be downloaded by clicking the following link.