Test Expression as user type

1

I'm having problems, trying to test an expression as the user types.

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

  • XXXX-XXXX-XXX

That is, it can be anything like:

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

And so it goes, so I created an event EditorKeyUp :

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

That triggers the Check_Pattern method:

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 the last character, it triggers the event, but the value obtained in String Input is the previous value.

It's as if I need to confirm the character entry.

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

    
asked by anonymous 25.04.2017 / 01:49

1 answer

0

To solve the problem I used the method: PostEditor

I used the PostEditor method to save the user input, and then I could do the comparison.

Well, if we do not call the method, PostEditor , it will only save the change when you 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());
            }
        }
    }'
    
25.04.2017 / 05:02