RadTextBoxControl - AutoComplete more than once

1 Answer 76 Views
TextBoxControl
João
Top achievements
Rank 1
Iron
Iron
Iron
João asked on 20 May 2022, 05:22 PM

Hey there!

I wanted to be able to Show the 'AutoCompleteDropDown' after having already used it, or having text behind the cursor. I wanted to use a space to separate such usage but I can't quite control this functionality in this object (RadTextBoxControl).

This is usefull to help the user to write complex formulas without having to check for specific names or values. And these formulas can have more than 300 characters so i want to 'help' the user on his "journey". 

Ex: vQuant * 300 - (vValue - 66) -> The 'vQuant' and 'vValue' are variables or constants that the user doesn't know by memory because there are more than 1000. He may know the first 2 letters or so tho.

I was able to show the object by doing 'THIS-OBJECT:radTextBoxControl1:TextBoxElement:AutoCompleteDropDown:Show().'  but it has 0 items (even by having text in the object and 'THIS-OBJECT:radTextBoxControl1:TextBoxElement:AutoCompleteItems:Items:count' being > 0).

I'm open to any ideas.

 

JP

1 Answer, 1 is accepted

Sort by
1
Accepted
Dinko | Tech Support Engineer
Telerik team
answered on 25 May 2022, 10:08 AM

Hi,

The following KB article demonstrates a sample approach how to achieve "Contains" autocomplete functionality in RadTextBoxControl. In a few words, you can create custom RadTextBoxControl and override the AutoCompleteFilterOverride method. Inside the method, you can get the entered text and execute custom logic to validate if an item from the dropdown should be suggested. Here is my suggestion for a custom logic inside the AutoCompleteFilterOverride method.

public class CustomTextBoxControl : RadTextBoxControl
{
    public override string ThemeClassName
    {
        get
        {
            return typeof(RadTextBoxControl).FullName;
        }
    }

    protected override RadTextBoxControlElement CreateTextBoxElement()
    {
        return new CustomTextBoxControlElement();
    }
}

public class CustomTextBoxControlElement : RadTextBoxControlElement
{
    protected override Type ThemeEffectiveType
    {
        get
        {
            return typeof(RadTextBoxControlElement);
        }
    }

    protected override RadTextBoxListElement CreateListElement()
    {
        return new CustomTextBoxListElement();
    }
}

public class CustomTextBoxListElement : RadTextBoxListElement
{
    protected override bool AutoCompleteFilterOverride(RadListDataItem item)
    {
        var patternTextArray = this.PatternText.Split(' ');
        string itemText = (item.Text ?? string.Empty).ToUpperInvariant();

        foreach (string patternText in patternTextArray)
        {
            if(itemText.Contains(patternText))
            {
                return true;
            }
        }
        return false;
    }
}

You can extend the logic depending on your requirement. Give this approach a try and let me know if it is working for you.

Regards,
Dinko
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

João
Top achievements
Rank 1
Iron
Iron
Iron
commented on 25 May 2022, 11:10 AM

Hey Dinko!

That was exacly what i wanted! Thank you very much.

One question tho, let's say that this wasn't on the telerik site (which is odd since i tried to find something about this and couldn't), how would i discover this on my own? I'm quite a newbie on programming itself that's why I'm asking for tips! :D

JP

Dinko | Tech Support Engineer
Telerik team
commented on 26 May 2022, 09:50 AM

My guidelines here will be to check the control properties and what public methods could be overrides. You can check the type of each custom object property and what properties the class exposes. In Visual Studio you can place the caret on a custom object and press the F12 key. A new tab will be open with all the properties which the control has. This will be a search process to get familiar with the control. This is the general case where you don't have the source code. It will be better to start with the documentation first. This way you can get familiar with all the functionalities of the control and then proceed with customization.
João
Top achievements
Rank 1
Iron
Iron
Iron
commented on 26 May 2022, 11:11 AM

Hey Dinko!

Duly noted! Thank you for the tips!

Have a great one!

 

JP

João
Top achievements
Rank 1
Iron
Iron
Iron
commented on 02 Jun 2022, 02:54 PM

Hey again Dinko!

Unfortunately I wasn't able to do the following:

-On value changed of the auto-complete (by down/up arrow (of keyboard)) the text property of the radtexboxcontrol, seems to replace the previous text with the selected one (on the autocomplete box), i want to replace only part of it so i can concatenate the user input.

Can you help me?

 

JP

Dinko | Tech Support Engineer
Telerik team
commented on 06 Jun 2022, 11:58 AM

I am not sure that I have fully understood your case. Could you give me some examples so that I can better understand them and think of a suitable solution? You can send me an image of a dummy text of the input and what you want to happen when the user clicks on the arrows to navigate between the suggested items in the dropdown area.
João
Top achievements
Rank 1
Iron
Iron
Iron
commented on 06 Jun 2022, 01:20 PM

Hey again Dinko!

Let's imagine a situation where I have text in the property 'text' of the object(radtextboxcontrol) and i keep writing on it and the "aucomplete" shows again (as it's expected), but when i use 'down key' to choose of the options in it, the object triggers the event that replaces everything that was in the property with the option i just choosed. 

I didn't want that to happen so I asked you if you had anything or knew anything that would fix it.

But since I was in a hurry i kept tryng and decompiled the DLL's and found the method that did that and I overrived it and manipulated what I wanted the way I wanted.

If anyone has the same problem or wants to achieve the same i just descibed, then here it is:

PS:Please ignore the variable names, since this is still in the testing phase :D
CLASS RadTextBoxListElement INHERITS Telerik.WinControls.UI.RadTextBoxListElement: 
 
    DEFINE PRIVATE VARIABLE a AS CHARACTER NO-UNDO INITIAL "*":U.
    DEFINE PRIVATE VARIABLE s AS CHARACTER NO-UNDO INITIAL " ":U.

    /*------------------------------------------------------------------------------
     Purpose:
    ------------------------------------------------------------------------------*/

    METHOD OVERRIDE PROTECTED LOGICAL AutoCompleteFilterOverride( INPUT item AS Telerik.WinControls.UI.RadListDataItem ):
        RETURN ITEM:TEXT MATCHES a + THIS-OBJECT:getNewPatternText(THIS-OBJECT:PatternText) + a.
    END METHOD.

    /*------------------------------------------------------------------------------
     Purpose:
    ------------------------------------------------------------------------------*/

    METHOD PRIVATE CHARACTER getNewPatternText( INPUT inputPatternText AS CHARACTER ):
        /*X X*/
        IF TRIM(inputPatternText) MATCHES a + s + a THEN RETURN ENTRY(NUM-ENTRIES(inputPatternText,s),inputPatternText,s).
        /*X*/
        ELSE RETURN inputPatternText.
    END METHOD.

    /*------------------------------------------------------------------------------
     Purpose:
    ------------------------------------------------------------------------------*/

    METHOD OVERRIDE PUBLIC VOID OnSuggestedTextChanged( INPUT e AS SuggestedTextChangedEventArgs ):
        SUPER:OnSuggestedTextChanged(e).

        ASSIGN 
            THIS-OBJECT:startPosition = (IF TRIM(e:TEXT) MATCHES a + s + a THEN e:EndPosition ELSE e:StartPosition)
            THIS-OBJECT:endPosition   = e:EndPosition.
        RETURN.

    END METHOD.

END CLASS.

Dinko | Tech Support Engineer
Telerik team
commented on 07 Jun 2022, 08:42 AM

Thank you for the provided details and thank you for sharing your solution. You are in the right direction. This behavior is not supported by the control and you will need to create custom logic to support this. 
Tags
TextBoxControl
Asked by
João
Top achievements
Rank 1
Iron
Iron
Iron
Answers by
Dinko | Tech Support Engineer
Telerik team
Share this question
or