I have a form that contain several textboxes that are bound to a database.row that has int32 as datatype and allows dbNull value. When a user starts up the form, the code inserts three values (this is because the user needs to know these values before filling in the rest), and fills the tableadapter with data so many textboxes is bound to dbNull value.
The form has many textboxes bound to a SQL-database and the form functions very well if you put correct data into the form. I also have checks on the textboxes that must have int as datatyp that the text is possible to parse as an int (so all checks is ok).
My problem is as follows:
1. If a user "tabs" his way throug the form and accidentally puts a
2. If they delete the character the textbox.validate() locks the control and I cannot get the form to do anything until the user puts in an int into the box. If the user puts in an int the validatoin works and form is
3. I want to set the textbox back to its previous state whenever the textbox.text.length == 0, because then it is the same as when you open the form and this validates fine (because it contains no data).
4.
Hope this was understandable.
1: | private void feilMldTall(TextBox textBoxSjekk, string feilKontroll) |
implement the validating event of textboxes:
private void textBoxSjekk_Validating(ob
{
if (textBoxSjekk.Text.Length > 0)
{
try
{ Int32.Parse(textBoxSjekk.T
catch (Exception)
{
MessageBox.Show("Can only contain int");
textBoxSjekk.Clear();
textBoxSjekk.Focus();
}
}
}
If you want to
public partial class Form1 : Form
{
string _previousValidTextBoxSjekk
public Form1()
{
InitializeComponent();
textBoxSjekk.Text = "2";
_previousValidTextBoxSjekk
}
private void textBoxSjekk_Validating(ob
{
if (textBoxSjekk.Text.Length > 0)
{
int i;
if(!Int32.TryParse(textBox
{
MessageBox.Show("Can only contain int");
textBoxSjekk.Text = _previousValidTextBoxSjekk
textBoxSjekk.Focus();
return;
}
_previousValidTextBoxSjekk
}
// _previousValidTextBoxSjekk
}
}
No comments:
Post a Comment