0

I have developing wpf application where i need to search some value (10 digit) in database from textbox and show message as per output. i have used text changed event but it does not fulfil my requirement.it does not wait for accept complete value its fire before accepting 10 digit not after complete value.

so can any one tell me any solution for that or any alternative solution.

here i m using button to check the value but i dont want this. i want to call this method without pressing button.

heltonbiker
  • 26,657
  • 28
  • 137
  • 252
SANDEEP
  • 1,062
  • 3
  • 14
  • 32

2 Answers2

0

If you know it will be a 10 digit number just check the .Length property of the TextBox and don't search the database until the user have entered 10 digits, even better you can also make sure that they are all digits with the Char.IsDigit function.

Additional if you would like to enable shorter numbers in some cases this Stackoverflow question explains how to trigger code when a user presses the enter key in a textbox.

Community
  • 1
  • 1
Karl-Henrik
  • 1,113
  • 1
  • 11
  • 17
0

You could put an if statement on the TextChanged event, and only peform the actual action if your current text meets some condition.

An option would be to use a guard clause:

private void TextChangedHandler(sender, args) {

    if (meets_condition() == false)
        return

    // only runs if meetscondition == true
    DoThings();
}

the guard clause will make the handler do nothing except when condition is met.

heltonbiker
  • 26,657
  • 28
  • 137
  • 252