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
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.
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
Hey Dinko!
Duly noted! Thank you for the tips!
Have a great one!
JP
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
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 :DCLASS 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.