Test Expression as user type

Asked

Viewed 51 times

1

I’m having problems trying to test an expression as the user type.

I have a TreeList where the user will enter a code, this code has the model:

  • XXXX-XXXX-XXX

I mean, it could be anything like:

  • A216-0450-001
  • X515-0477-A44
  • F6FJ-0000-11C

And so on, so I created an event EditorKeyUp:

treeList1.EditorKeyUp += new KeyEventHandler(this.Check_Pattern);

That fires the method Check_Pattern:

private void Check_Pattern()
{
    TreeListNode tete = treeList1.FocusedNode;

    string input = tete.GetDisplayText("Descrição").ToString();

    string pattern = @"^.{4}-.{4}-.{3}$";

    if (Regex.IsMatch(input, pattern))
    {
        MessageBox.Show("top " + input);
    }
    else
    {
    }
}

But when I type in the last character, it triggers the event, however, the value obtained in String Input is the previous value.

It’s like I need to confirm the character input.

For example: I typed A216-0450-001 the value obtained is A216-0450-00, there when I type A216-0450-0012 he returns A216-0450-001

I needed when the last digit was typed, in this case the character 1, were fired the event.

1 answer

0


To solve the problem I used the method: Posteditor

I used the method PostEditor, to save the user input, and then be able to compare.

Yeah, if we don’t make the method call, PostEditor, it will only save the change, when change the focus of the cell.

    private void Compare_String(object sender, EventArgs e)
    {            
        treeList1.PostEditor();

        TreeListNode tete = treeList1.FocusedNode;

        string input = tete.GetDisplayText("Descrição").ToString();

        // se o flyout estiver visivel e o usuario começar a digitar ele oculta, se o input for menor que 10 caracteres ou maior que 18 caracteres
        if (input.Length < 10 || input.Length > 18)                
        {
            flyoutPanel1.HideBeakForm();
        }

        string pattern_1 = @"^.{4}-.{4}-.{0}$"; // xxxx-xxxx-         
        string pattern_2 = @"^.{4}-.{4}-.{1}$"; // xxxx-xxxx-x
        string pattern_3 = @"^.{4}-.{4}-.{2}$"; // xxxx-xxxx-xx
        string pattern_4 = @"^.{4}-.{4}-.{3}$"; // xxxx-xxxx-xxx
        string pattern_5 = @"^.{4}-.{4}-.{3}-$"; // xxxx-xxxx-xxx-
        string pattern_6 = @"^.{4}-.{4}-.{3}-.{1}$"; // xxxx-xxxx-xxx-x
        string pattern_7 = @"^.{4}-.{4}-.{3}-.{2}$"; // xxxx-xxxx-xxx-xx
        string pattern_8 = @"^.{4}-.{4}-.{3}-.{3}$"; // xxxx-xxxx-xxx-xxx
        string pattern_9 = @"^.{4}-.{4}-.{3}-.{4}$"; // xxxx-xxxx-xxx-xxxx
        string pattern_MP = @"^.{2}-.{0}$"; // xx-

        if (Regex.IsMatch(input, pattern_1) || Regex.IsMatch(input, pattern_MP) || Regex.IsMatch(input, pattern_2) || Regex.IsMatch(input, pattern_3) || Regex.IsMatch(input, pattern_4)
            || Regex.IsMatch(input, pattern_5) || Regex.IsMatch(input, pattern_6) || Regex.IsMatch(input, pattern_7) || Regex.IsMatch(input, pattern_8) || Regex.IsMatch(input, pattern_9))
        {
            //exibi o flyout, no ponto medio da celula em x, e no top em y
            flyoutPanel1.ShowBeakForm(treeList1.PointToScreen(new Point(Get_Middle_Node(), Get_Rectangle_Node().Top)));

            //como o metodo Populate_Grid_Itens, esta ligado ao evento  Showing, que é disparado somente quando o flyuout é exibido, se ele 
            //ja estiver visivel, precisamos disparar o metodo abaixo, para repopular o grid
            if (flyoutPanel1.Visible == true)
            {
                Populate_Grid_Itens(this, new FlyoutPanelEventArgs());
            }
        }
    }`
  • Friend, I made a review, please check if it clarifies the problem.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.