对errorprovider不大熟悉,请问各位,如何完成textbox1输入数值不为int型时报错。
是输入时(ing)用的errorprovider。

解决方案 »

  1.   

    ErrorProvider的一种最简单使用方法就是当用户向某控件比如TextBox中输入无效数据时显示错误提示,这种情况下甚至不需要设置 DataSource,只需要设置ContainerControl属性值为当前Form并使用SetError方法进行简单编码即可,如下所示。protected void textBox1_Validating (object sender,
       System.ComponentModel.CancelEventArgs e)
    {
       try
       {
          int x = Int32.Parse(textBox1.Text);
          errorProvider1.SetError(textBox1, "");
       }
       catch (Exception e)
       {
          errorProvider1.SetError(textBox1, "Not an integer value.");
       }
    }        在窗体上一个TextBox控件的验证事件处理方法中我们检查用户填入内容是否是数值,如果不是则在该TextBox控件旁显示错误图标,相应的 ToolTip文本就是“Not an integer value”。从另外一个角度,我们也可以猜到如果要手工消除错误信息,也是通过SetError方法将提示文本设为空字符串即可。
      

  2.   


    提示以下错误,怎么处理呢
    A local variable named 'e' cannot be declared in this scope because it would give a different meaning to 'e', which is already used in a 'parent or current' scope to denote something else
      

  3.   

    protected void textBox1_Validating (object sender,
       System.ComponentModel.CancelEventArgs e)
    {
       try
       {
          int x = Int32.Parse(textBox1.Text);
          errorProvider1.SetError(textBox1, "");
       }
       catch (Exception ex)
       {
          errorProvider1.SetError(textBox1, "Not an integer value.");
       }
    }