This is a migrated thread and some comments may be shown as answers.

Autocomplete with custom objects

1 Answer 151 Views
AutoCompleteBox
This is a migrated thread and some comments may be shown as answers.
Robert Schoen
Top achievements
Rank 1
Robert Schoen asked on 20 Jul 2013, 06:15 PM

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()

{

       radCCList.Clear();

       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;

                     m_objTicket.CCList.Remove(removeContact);

                                 

              }

       }

}

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.

 

 

1 Answer, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 24 Jul 2013, 03:16 PM
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
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
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 >>

RadTokenizedTextItem
Tags
AutoCompleteBox
Asked by
Robert Schoen
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Share this question
or