Autocomplete with custom objects

2 posts, 0 answers
  1. Robert Schoen
    Robert Schoen avatar
    17 posts
    Member since:
    Sep 2008

    Posted 20 Jul 2013 Link to this post

    I am trying to use an Autocompletebox similar to a list view.  I am doing this because of its compact form and look and feel.  I am not using the Auto complete or suggestion options.  I am using a separate dialog box to populate the control with data.  I am also wanting use this control as an attachment manager.  Something similar to the way outlook presents attachments.

    Populating the control seems to be fairly easy.  Although I would have expected a function to add to the internal collection rather than just an append method.

    Here is how I am populating my AutoCompleteBox.

    private void BuildCCList()



           foreach(Contact curContact in m_objTicket.CCList)


                  radCCList.AppendText(curContact + ";");






    This works pretty good; but, when I attempt to access those objects in the delete functions I have issues.  I am not able to cast the item being deleted back to my Contact Class.  It seems that the internal collection for the Autocompletebox is strings only.  There seems to be a value field but I have not figured out how to set that.


    ((RadAutoCompleteBoxElement)this.radCCList.TextBoxElement).Items.CollectionChanged += Items_CollectionChanged;


    private void Items_CollectionChanged(object sender, Telerik.WinControls.Data.NotifyCollectionChangedEventArgs e)


           if (e.Action == NotifyCollectionChangedAction.Remove)



                  foreach(object objContact in e.NewItems)


                         Contact removeContact = (Contact)objContact;






    Is there any other way of populating the control that would allow me to add my custom objects to the internal list?  Is there another control that I may be able to get a similar look and feel from?   In the end I am looking for a compact list of objects that can be add to and deleted from with a minimal foot print on the form.

    Any help would be appreciated.



  2. Dimitar
    Dimitar avatar
    1321 posts

    Posted 24 Jul 2013 Link to this post

    Hi Robert,

    Thank you for writing.

    Considering your code samples I have created a demo project. In the project I have bound the autocompletebox to a binding list. I have populated the the autocompletebox with values similar to your method. Now the casting is achieved by first casting to RadTokenizedTextItem then to the custom object like this:
    RadTokenizedTextItem test = objContact as RadTokenizedTextItem;
    Contact rem = test.Value as Contact;

    In the attached demo your logic is completed and the items are removed from both, the bindinglist and the autocompletebox.

    If you have any questions, please do not hesitate to contact us.

    Regards, Dimitar
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>

  3. DevCraft R3 2016 release webinar banner
Back to Top