PageViewPage - ErrorProvider.SetError()

2 posts, 0 answers
  1. Doug
    Doug avatar
    50 posts
    Member since:
    Jul 2012

    Posted 20 Aug 2013 Link to this post

    I'm open to alternatives.

    I would like to use the ErrorProvider to set error text on the tabs of PageViewPages.  Can that be done?

    (As an alternative, I can modify the text on the tab to indicate that the page has errors on it.)

    Thank you,
    Gary
  2. Dess
    Admin
    Dess avatar
    1609 posts

    Posted 23 Aug 2013 Link to this post

    Hello Gary,

    Thank you for contacting Telerik Support.

    Please refer to the following code example demonstrating how to manage errorProvider for each RadPageViewPage:
    public Form1()
    {
        InitializeComponent();
         
        errorProvider1.BlinkStyle = ErrorBlinkStyle.AlwaysBlink;
     
        this.radPageView1.SelectedPageChanging += radPageView1_SelectedPageChanging;
        this.radPageView1.ViewMode = PageViewMode.Strip;
    }
     
    private void radPageView1_SelectedPageChanging(object sender, Telerik.WinControls.UI.RadPageViewCancelEventArgs e)
    {
        RadPageView pageView = sender as RadPageView;
        if (!ValidatePage(pageView.SelectedPage))
        {
            int index = this.radPageView1.Pages.IndexOf(this.radPageView1.SelectedPage);
            int X = ((RadPageViewStripElement)this.radPageView1.ViewElement).Children[0].Children[0].Children[index].BoundingRectangle.X;
     
            e.Cancel = true;
            errorProvider1.SetIconAlignment(pageView.SelectedPage, ErrorIconAlignment.TopLeft);
            errorProvider1.SetIconPadding(pageView.SelectedPage, -X - 50);
            errorProvider1.SetError(pageView.SelectedPage, string.Format("Invalid {0}", pageView.SelectedPage.Text));
        }
        else
        {
            errorProvider1.SetError(pageView.SelectedPage, string.Empty);
        }
    }
     
    private bool ValidatePage(RadPageViewPage radPageViewPage)
    {
        switch (radPageViewPage.Text)
        {
            case "radPageViewPage1":
                if (radTextBox1.Text == string.Empty)
                {
                    return false;
                }
                return true;
            case "radPageViewPage2":
                if (radToggleButton1.ToggleState == Telerik.WinControls.Enumerations.ToggleState.Off)
                {
                    return false;
                }
                return true;
            case "radPageViewPage3":
                return false;
     
            default:
                return true;
        }
    }

    Note that positioning the .NET errorProvider icon is not quite customizable, so I were forced to use icon padding in order to position correctly the exclamation mark under the middle of each RadPageViewPage header.

    I hope this information helps. Should you have further questions, I would be glad to help.

    Regards,
    Desislava
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top