[Mono-winforms-list] Issues with Control focus and error provider location

Jijesh incubator125 at hotmail.com
Tue Jun 9 05:35:05 EDT 2009


Hi Friends,

I have a dataentry application developed in C# winforms. In that, most of
the testbox fields are validated using conditions and error providers. When
i tried the application in ubuntu using mono, the validations are not
working. In actual situation the focus should not go from the control if the
validation fails. but the focus goes off in this scenario.

Please look into the sample code i wrote for this scenario to test. Here i
have two text boxes in a group box and one error provider. The textbox entry
is validating on the "textBox1_Validating" event handler.

public partial class Form1 : Form
    {
        private System.Windows.Forms.TextBox textBox1;
        private System.Windows.Forms.Button button1;
        private System.Windows.Forms.ErrorProvider errorProvider1;
        private System.Windows.Forms.GroupBox groupBox1;
        private System.Windows.Forms.TextBox textBox2;

        public Form1()
        {
            InitializeComponent();
        }

        private void textBox1_Validating(object sender, CancelEventArgs e)
        {
            if (textBox1.Text != "")
            {
                try
                {
                    DateTime validatedate =
Convert.ToDateTime(textBox1.Text.Trim());
                    if (validatedate.Year < 1900)
                    {

                        MessageBox.Show("Enter a valid Date");
                        textBox1.Focus();
                        return;
                    }
                    else
                        errorProvider1.SetError(textBox1, "");
                }
                catch
                {

                    errorProvider1.SetError(textBox1, "Enter a valid Date");
                    textBox1.Focus();
                }
            }
            else
                errorProvider1.SetError(textBox1, "");
        }

        private void textBox2_Validating(object sender, CancelEventArgs e)
        {
            if (textBox2.Text != "")
            {
                try
                {
                    DateTime validatedate =
Convert.ToDateTime(textBox2.Text.Trim());
                    if (validatedate.Year < 1900)
                    {

                        errorProvider1.SetError(textBox2, "Enter a valid
Date2");

                        textBox2.Focus();
                        return;
                    }
                    else
                        errorProvider1.SetError(textBox2, "");
                }
                catch
                {

                    errorProvider1.SetError(textBox2, "Enter a valid 
Date2");
                    textBox2.Focus();
                }
            }
            else
                errorProvider1.SetError(textBox2, "");
        }
        

                Here the focus is not staying back on the control if the
validation fails and,error provider is not shown at the correct position.


Thanks in advance,
Jijesh



-- 
View this message in context: http://www.nabble.com/Issues-with-Control-focus-and-error-provider-location-tp23939522p23939522.html
Sent from the Mono - WinForms mailing list archive at Nabble.com.



More information about the Mono-winforms-list mailing list