Remove Token from AutocompleteTextView Programmatically

3 posts, 0 answers
  1. Mayank
    Mayank avatar
    4 posts
    Member since:
    Nov 2018

    Posted 20 Dec 2018 Link to this post

    Hello Team,

    I am getting Issue while Remove Token Programmatically.

    Steps i Follow:

    1) I am Adding my Token Programmatically, which is successfully Add in the AutoCompleteTextView,
    I am adding Token using Below Method.
    => this.Autocomplete.AddToken(new TKAutoCompleteToken(new NSString("DummyToken")));

    2) Now when i try to remove the same Token Programmatically, I ma using Below Code,
    => this.Autocomplete.RemoveToken(new TKAutoCompleteToken(new NSString(DummyToken)));

    But it is not removing from AutoCompleteTextView.

    I spent many hours but not getting success,

    So, if anyone can help me on this, it will be appreciated.


  2. Lance | Principal TSE
    Lance | Principal TSE avatar
    1043 posts

    Posted 20 Dec 2018 Link to this post

    Hi Mayank,

    I would investigate to make sure that token reference is even valid, it doesn't look like it would work to me.  You should instead use the NSArray that holds the tokens to get an actual reference to the token you want to remove.

    For example, here's how to get a reference to the last token in the array:

    var tokens = _autocomplete.Tokens();
    var lastTokenIndex = tokens.Count - 1;
    var lastToken = tokens.GetItem<TKAutoCompleteToken>(lastTokenIndex);

    Now, with a valid reference to the token in the Tokens array, you can use it for RemoveToken() method:


    I've attached a demo, to see it working:

    1 - Select 2 items in the AutoCompleteView
    2 - Click the button to remove the last token

    If you would like more guidance on finding specific items in an NSArray, here's a good example in StackOverflow.

    Lance | Tech Support Engineer, Sr.
    Progress Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. Mayank
    Mayank avatar
    4 posts
    Member since:
    Nov 2018

    Posted 03 Jan in reply to Lance | Principal TSE Link to this post

    Thanks, its working with your solution.
Back to Top