Validation Of TabPage on TabSelecting

10 posts, 0 answers
  1. Ajay
    Ajay avatar
    29 posts
    Member since:
    Mar 2009

    Posted 16 Feb 2010 Link to this post

    HI,
        I have one issue regarding RadTabStrip. I have created two pages(Page 1 and Page 2) in RadTabstrip.In both the pages i have added two Radio Buttons and One Text box.Now I have subscribed Validating event of Text boxes of both the pages. I also have subscribed TabSelecting event of RadTabStrip.
                                                      Now in my scenario if validation of current Text Box is not done,I should not be able to select different tabPage.so to achieve this i have made  args.Cancel = true; this statement in TabSelecting Event.

    C# Code :

    private void radTabStrip1_TabSelecting(object sender, Telerik.WinControls.UI.TabCancelEventArgs args)
            {
                if (!Valid)
                {
                    args.Cancel = true;
                }
            }

    Here Valid is globla variable showing i need to stop tabChange.

    Problem :

    Suppose now i am on Page 1 and entered some Invalid entry in TextBox and I click on  page 2. Validation fires from Text Box and force me to be on page 1. Here Page 2 is not selected.This is fine for me,But now if i made Valid Entry in Text Box then I am able to change tab but not able to click( or change) Raido button on Page 1. Here I am suppose to change or select Radio button on same page in case of valid entry in Text Box.

  2. Dobry Zranchev
    Admin
    Dobry Zranchev avatar
    348 posts

    Posted 17 Feb 2010 Link to this post

    Hello Ajay,

    Thank you for writing. We could not reproduce the issue. Could you modify the attached example to reproduce that issue. Thank you in advanced. If you have any other questions feel free to ask.

    Regards,
    Dobry Zranchev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Ajay
    Ajay avatar
    29 posts
    Member since:
    Mar 2009

    Posted 17 Feb 2010 Link to this post

    My Finding is that without using MessageBox it runs fine but wiht messageBox it loses focus and not able to select Radio button. Please revarify through my above given details.




    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;

    namespace WindowsFormsApplication10
    {
        public partial class Form1 : Form
        {
            private bool valid;
           
            public Form1()
            {
                InitializeComponent();
            }

            private void radTabStrip1_TabSelecting(object sender, Telerik.WinControls.UI.TabCancelEventArgs args)
            {
                if (!valid)
                {
                    args.Cancel = true;
                }
            }

            private void radTextBox1_Validated(object sender, EventArgs e)
            {
           
            }

            private void radTextBox2_Validated(object sender, EventArgs e)
            {
               
            }

            private void radTextBox2_Validating(object sender, CancelEventArgs e)
            {
                valid = true;
                if (radTextBox2.Text.Length > 2)
                {
                    e.Cancel = true;
                    MessageBox.Show("Error: Length cant be more than 2","Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
                    radTextBox2.SelectAll();
                    valid = false;
                }
            }

            private void radTextBox1_Validating(object sender, CancelEventArgs e)
            {
                valid = true;
                if (radTextBox1.Text.Length > 2)
                {
                    e.Cancel = true;
                    MessageBox.Show("Error: Length cant be more than 2", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    radTextBox1.SelectAll();
                    valid = false;
                }
            }

           
        }
    }

  5. Dobry Zranchev
    Admin
    Dobry Zranchev avatar
    348 posts

    Posted 17 Feb 2010 Link to this post

    Hi Ajay,

    Thank you for contacting us. That's expected behavior. Every-time when you lost focus, the event Validating is fired and you can cancel validation in your code and leave RadTextBox control in edit mode. The message box has no meaning.

    You can read more about validation here:
    http://msdn.microsoft.com/en-us/library/system.windows.forms.control.validating.aspx

    Kind regards,
    Dobry Zranchev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  6. Ajay
    Ajay avatar
    29 posts
    Member since:
    Mar 2009

    Posted 09 Mar 2010 Link to this post

    Hi,
        I know The message box has no meaning, But in our application it is required to show messgebox type of prompt to user.This functionality can be achieved in Windows TabContro by using Deseleting event of TabControl. May i know is there any event similar to
    Deselecting event or any other property or function  or some work around to achieve this functionality.

    Thanks,
    Ajay
  7. Dobry Zranchev
    Admin
    Dobry Zranchev avatar
    348 posts

    Posted 09 Mar 2010 Link to this post

    Hi Ajay,

    You should check witch tab is clicked and validate according to that. If the selected tab is the first tab, you need to validate according to the text box that is in the second one and reverse. Please look at the following code:

    private void radTabStrip1_TabSelecting(object sender, Telerik.WinControls.UI.TabCancelEventArgs e)
    {
        if (e.TabItem == this.tabItem2)
        {
            if (radTextBox1.Text.Length > 2)
            {
                e.Cancel = true;
                MessageBox.Show("Error: Length cant be more than 2", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.radTextBox1.Focus();
                radTextBox1.SelectAll();
                valid = false;
            }
        }
        else if (e.TabItem == this.tabItem1)
        {
            if (radTextBox2.Text.Length > 2)
            {
                e.Cancel = true;
                MessageBox.Show("Error: Length cant be more than 2", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.radTextBox2.Focus();
                radTextBox2.SelectAll();
                valid = false;
            }
        }
    }

    I hope that this helps.

    Sincerely yours,
    Dobry Zranchev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  8. Ajay
    Ajay avatar
    29 posts
    Member since:
    Mar 2009

    Posted 10 Mar 2010 Link to this post

    Hi,
        as per your suggestion, I have tried it but, It also did n't work.Here main problem is if we set e.Cancel to true in selecting event, Now if I made a valid entry on the same page then controls are not working (or active ie. Radio button in Previous example), thats my finding is. If I have not understand your solution update me the last code which i have sent you in earlier response.

    Thanks,
    Ajay
  9. Dobry Zranchev
    Admin
    Dobry Zranchev avatar
    348 posts

    Posted 10 Mar 2010 Link to this post

    Hello Ajay,

    Thank you for contacting us back. May be I did not understand you. Could you provide an example?

    Sincerely yours,
    Dobry Zranchev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  10. Ajay
    Ajay avatar
    29 posts
    Member since:
    Mar 2009

    Posted 12 Mar 2010 Link to this post

    Hi.
        Actully i want to achive functionality in TabStrip, which i have achived by windows TabControl. 
     
       Objective:  If i made invalid entry user should not be able to click any where and he will be on the validating control.
       Step to reporduce the issue :
                               1. after making Invalid entery click on other tab, It should prompt message (MessageBox it is required for application).
                               2. Now make some valid entry and change other control like Radio button,Combo Box (But not Text Box) on page.
                               3. Here after message prompt if user made valid entry. User is not able to change control on page.

    Hope you would have understood my concern.
    Note : Giving you the code which i have done with Windows TabControl.
    Regards,
    Ajay 
      
                               
    using System;  
    using System.Collections.Generic;  
    using System.ComponentModel;  
    using System.Data;  
    using System.Drawing;  
    using System.Linq;  
    using System.Text;  
    using System.Windows.Forms;  
    using Telerik.WinControls.UI;  
     
    namespace WindowsFormsApplication44  
    {  
        public partial class Form1 : Form  
        {  
            public Form1()  
            {  
                InitializeComponent();  
            }  
     
            bool cancel = true;  
            private void tabControl1_Deselecting(object sender, TabControlCancelEventArgs e)  
            {  
                TabControl tc = (TabControl)sender;  
                if (tc.SelectedIndex != 0)  
                {  
                    return;  
                }  
                e.Cancel = cancel;  
                cancel = false;  
            }  
     
            private void Form1_FormClosing(object sender, FormClosingEventArgs e)  
            {  
                if (this.tabControl1.SelectedIndex != 0)  
                {  
                    return;  
                }  
                e.Cancel = cancel;  
                cancel = false;  
            }  
     
            private void textBox2_Validating(object sender, CancelEventArgs e)  
            {  
                if (textBox2.Text.Length == 2)  
                {  
                    MessageBox.Show("Error");  
                    cancel = true;  
                    textBox2.Focus();  
                    textBox2.SelectAll();  
                }  
                else  
                {  
                    cancel = false;  
                }  
            }  
        }  
    }  
     
  11. Dobry Zranchev
    Admin
    Dobry Zranchev avatar
    348 posts

    Posted 12 Mar 2010 Link to this post

    Hi Ajay,

    Thanks for your feedback. We will decide later whether we will add that functionality (Deselecting, Deselected events).

    The right work-around is to use TabSelecting event of RadTabStrip and check the argument for the selected TabItem, the currently selected item, and validate accordingly.

    If this does not help, please send us a sample project and I will update it.

    Best wishes,
    Dobry Zranchev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Back to Top
UI for WinForms is Visual Studio 2017 Ready