Connecting Tech Pros Worldwide Forums | Help | Site Map

event control

Newbie
 
Join Date: Oct 2009
Posts: 25
#1: 3 Weeks Ago
hi,
i m new in c sharp. I m working in a project in which there are 4 textbox , which are to filled serially. If the user filled the wrong value in first textbox , a message should be displayed and the control should remain in the same textbox. or in other words user should be forced to fill the boxes serially. i hope i explained the problem.
so,plz, help me in getting out of this prob.
thanx

tlhintoq's Avatar
Moderator
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 1,778
#2: 3 Weeks Ago

re: event control


Use the .Enabled property to disable the other textboxes
.Enabled = false;

When the user has given a proper answer to the first textbox you can disable it, enable the second and use the .Focus property to put the cursor in that box.
Newbie
 
Join Date: Oct 2009
Posts: 25
#3: 3 Weeks Ago

re: event control


thanx for the previous reply.
but using .Focus(textbox2.focus in textbox1) gives error Error "Cannot assign to 'Focus' because it is a 'method group' "
tlhintoq's Avatar
Moderator
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 1,778
#4: 3 Weeks Ago

re: event control


Right.
It is a method. The error tells you this.
Methods take parameters within parentheses.
Expand|Select|Wrap|Line Numbers
  1. textbox2.focus();
Newbie
 
Join Date: Oct 2009
Posts: 25
#5: 3 Weeks Ago

re: event control


hi,
i have 4 textboxes in my project.
if a wrong entry is made in a textbox, then as soon as i move to nexttextbox a error box is displayed. and all the entries should be made serially.
i used enabled key bt in that case mouse cant be used.
then i used foll code:
Expand|Select|Wrap|Line Numbers
  1. private void textBox1_Leave(object sender, EventArgs e)
  2.         {
  3.  
  4.                 text1();               
  5.                 label6.Visible = false;
  6.                 button4.Enabled = true;
  7. }
  8. public void text1()
  9.         {
  10.             if (textBox1.Text == "")
  11.             {
  12.                  System.Windows.Forms.DialogResult result = MessageBox.Show(this, "Enter tttValue between[ 1 to 3000]", "Start Value error", MessageBoxButtons.OK,
  13.                     MessageBoxIcon.Error);
  14.                 if (result == System.Windows.Forms.DialogResult.OK)
  15.                     textBox1.Focus();             
  16.                           return;
  17.             }            
  18.                 s = float.Parse(textBox1.Text);
  19.                 if (!(s > 0 && s < 3000))
  20.                 {
  21.                                         System.Windows.Forms.DialogResult result = MessageBox.Show(this, "Enter Value between[ 1 to 3000]", "Start Value error", MessageBoxButtons.OK,
  22.                     MessageBoxIcon.Error);
  23.                     if (result == System.Windows.Forms.DialogResult.OK)
  24.                         textBox1.Focus();                    
  25.                     return;
  26.                 }
  27.  
  28.         }
but in this case if i move from textbox2 to textbox1 its not allowing me due to leave func.
so is there any other way i can do that
tlhintoq's Avatar
Moderator
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 1,778
#6: 3 Weeks Ago

re: event control


TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out.
tlhintoq's Avatar
Moderator
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 1,778
#7: 3 Weeks Ago

re: event control


Quote:
if i move from textbox2 to textbox1 its not allowing me due to leave func.
Quote:
and all the entries should be made serially.
Well which is it? If all entries are to be made in sequence then you aren't allowing people to back up from textbox2 to textbox1.

if you are allowing people to do so but only under certain conditions then you need to check for those conditions and if they are met, then re-enable textbox1.
tlhintoq's Avatar
Moderator
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 1,778
#8: 3 Weeks Ago

re: event control


Also... You already a thread started for this question. There was no reason to start a second one for the same issue/problem. I have merged the two threads. In the future please keep to the basic guide lines of "One thread per issue/One issue per thread."
Reply