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

Pageview page checkbox

4 Answers 92 Views
PageView
This is a migrated thread and some comments may be shown as answers.
Nicklas
Top achievements
Rank 1
Veteran
Nicklas asked on 19 Sep 2020, 02:41 PM

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

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 21 Sep 2020, 11:22 AM

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/.

0
Nicklas
Top achievements
Rank 1
Veteran
answered on 22 Sep 2020, 01:56 PM

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

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 23 Sep 2020, 01:46 PM

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/.

0
Nicklas
Top achievements
Rank 1
Veteran
answered on 23 Sep 2020, 02:26 PM
Thanks I figured out a similar solution
Tags
PageView
Asked by
Nicklas
Top achievements
Rank 1
Veteran
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Nicklas
Top achievements
Rank 1
Veteran
Share this question
or