Note that there are some explanatory texts on larger screens.

plurals
  1. POvalidate textbox text and increase the tab index once
    primarykey
    data
    text
    <p>hi i know where my code is going wrong, but don't know how to fix it...</p> <p>on the TextChanged event, i call my validation function which does (is supposed to do) the following:</p> <ul> <li>remove any non letter character</li> <li>convert the entered letter to upper case</li> <li>only allow one character in the textbox</li> <li>use SendKeys to increase the tab index (go to next textbox)</li> </ul> <p>problem is since it is in the textchanged event, i'm trying to fight it to prevent it from tabbing twice (which it is doing). because the if i step through, the initial letter entered is the first textchanged event, then if it is a notallowedcharacter, the function is called again, but if it is a letter, the ToUpper may be changing it again so tab is getting sent twice. any ideas? i know there's a way to do this without setting up some complex bools....</p> <pre><code>private void validateTextInteger(object sender, EventArgs e) { TextBox T = (TextBox)sender; try { //Not Allowing Numbers, Underscore or Hash char[] UnallowedCharacters = { '0', '1','2', '3', '4', '5','6', '7','8', '9','_','#','%','$','@','!','&amp;', '(',')','{','}','[',']',':','&lt;','&gt;','?','/','=','-','+','\\','|','`','~',';'}; if (textContainsUnallowedCharacter(T.Text, UnallowedCharacters)) { int CursorIndex = T.SelectionStart - 1; T.Text = T.Text.Remove(CursorIndex, 1); //Align Cursor to same index T.SelectionStart = CursorIndex; T.SelectionLength = 0; } } catch (Exception) { } T.Text = T.Text.ToUpper(); if (T.Text.Length &gt; 0) { //how do i prevent this (or this function) from getting called twice??? SendKeys.Send("{TAB}"); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload