Hi,
I'm trying to implement a behavior that will enable me to "check" each page of a pageview. The purpose of this is to define witch pages an user can access.
Basically I want to replace the close button with a checkbox, and then somehow be able to write to the console what pages are checked.
Thanks in advance!
4 Answers, 1 is accepted
Hello, John,
Please have a look at the following code snippet demonstrating how to add check boxes for the page tabs and detect which page is toggled:
public RadForm1()
{
InitializeComponent();
RadPageViewStripElement stripElement = this.radPageView1.ViewElement as RadPageViewStripElement;
foreach (RadPageViewItem item in stripElement.Items)
{
RadCheckBoxElement cb = new RadCheckBoxElement();
cb.ToggleStateChanged+=cb_ToggleStateChanged;
item.ButtonsPanel.Children.Add(cb);
}
}
private void cb_ToggleStateChanged(object sender, StateChangedEventArgs args)
{
RadCheckBoxElement cb = sender as RadCheckBoxElement;
RadPageViewStripItem pageStripItem = cb.Parent.Parent as RadPageViewStripItem;
Console.WriteLine(pageStripItem.Page.Text);
}
I hope this information helps. If you need any further assistance please don't hesitate to contact me.
Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.
Thanks it works!
But how can I write the checked pages to the console outside the toggle event? I want to do this on the click of a button
Hi, John,
You can store the ToggleState in the RadPageViewPage.Tag property. Thus, you can iterate the pages in button's Click event and get the respective check value:
public RadForm1()
{
InitializeComponent();
RadPageViewStripElement stripElement = this.radPageView1.ViewElement as RadPageViewStripElement;
foreach (RadPageViewItem item in stripElement.Items)
{
RadCheckBoxElement cb = new RadCheckBoxElement();
cb.ToggleStateChanged+=cb_ToggleStateChanged;
item.ButtonsPanel.Children.Add(cb);
item.Page.Tag = ToggleState.Off;
}
}
private void cb_ToggleStateChanged(object sender, StateChangedEventArgs args)
{
RadCheckBoxElement cb = sender as RadCheckBoxElement;
RadPageViewStripItem pageStripItem = cb.Parent.Parent as RadPageViewStripItem;
pageStripItem.Page.Tag = args.ToggleState;
}
private void radButton1_Click(object sender, EventArgs e)
{
foreach (RadPageViewPage p in this.radPageView1.Pages)
{
Console.WriteLine(p.Text + " "+p.Tag );
}
}
I believe that it would fit your scenario.
Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.