AutoCompleteBox SelectedValues

9 posts, 0 answers
  1. Exchange
    Exchange avatar
    11 posts
    Member since:
    Oct 2012

    Posted 01 Apr 2013 Link to this post

    How do you retrieve the selected values for the auto complete box??

    I  have the DisplayMember and DisplayValue set:
    racSchTechs.AutoCompleteDataSource = datatable;
    racSchTechs.AutoCompleteDisplayMember = "Name_Full";
    racSchTechs.AutoCompleteValueMember = "id_lanid";

    but I want to get the "id_lanid" from the items selected. I do not see this functionality. 

    Thank you!
  2. Stefan
    Stefan avatar
    2911 posts

    Posted 04 Apr 2013 Link to this post


    Thank you for writing.

    The selected items in the control can be found in the Items collection. Each item contain text and a value, so you can get both the display and the value member.

    I hope this helps.

    the Telerik team
    WinForms Q1 2013 boasts PivotGrid, PDF Viewer, Chart enhancements and more. Check out all of the latest highlights.
  3. Tommy
    Tommy avatar
    1 posts
    Member since:
    Aug 2011

    Posted 28 Aug 2013 Link to this post


    How are you suppose to know the item number to get the value

    AutoDoorComplete.AutoCompleteDataSource = DoorNameList;

    AutoDoorComplete.AutoCompleteDisplayMember = "DoorName";

    AutoDoorComplete.AutoCompleteValueMember = "DoorID";

    When I select a DoorName I want the selected AutoCompleteValueMember DoorID

    DoorID = Convert.ToInt32(AutoUser.Items[0].Value.ToString()); How can this work if I do not know the Items[number] ?
    Why is it so hard to get the value when selected ?

     As the other user said the "SELECTED Value"

  4. Stefan
    Stefan avatar
    2911 posts

    Posted 29 Aug 2013 Link to this post

    Hello Tommy,

    Thank you for writing.

    RadAutoCompleteBox can have more than one item selected at a time. Please have a look at the attached picture (2013-08-29_0849.png), where the control have three values selected (name0, name2, name9). The selected items are stored in the Items collection of the control, so at this moment it has three items in it. Each item has a Text property which holds the value from the field specified as AutoCompleteDisplayMember and a Value property which holds the value from the field specified as AutoCompleteValueMember. Have a look at image 2013-08-29_0855.png, where you can see the selected items text and values. 

    I hope that you find this information useful.

    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 >>
  5. Kamelia
    Kamelia avatar
    7 posts
    Member since:
    Sep 2014

    Posted 12 Nov 2014 in reply to Stefan Link to this post

    Hi, Is it possible to preselect items in a radautocompletebox in windows form ???

    I have some items which I want to have them in my radautocompletebox , so I can remove or add items in it . AND I need it to show me the items I had entered before.
    thank you in advance
  6. Stefan
    Stefan avatar
    2911 posts

    Posted 12 Nov 2014 Link to this post

    Hi Kamelia,

    Thank you for writing.

    I am not quite sure I understand what is your requirement. However, you can use the formatting event and style some of the tokens with different back color to indicate selection. Alternatively, you can select one or more consecutive items by selecting their text, as demonstrated here:

    If this is not what you need, please provide more details on the precise requirement and I will do my best to help you achieve it.


    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

  7. Jørgen Granborg
    Jørgen Granborg avatar
    2 posts
    Member since:
    Sep 2004

    Posted 26 May 2015 in reply to Stefan Link to this post

    I believe the OP has the same problem that we have run into:

     When we close our form, we want to save the items that are currently selected. This is easy, using the Items collection. We need to save both the Text and the Value.

    When we then re-open the form, we need to restore it to the same settings as when it was closed, ie. the AutoCompleteBox should be filled with the same items that were saved when we closed it - both text AND value members of the Items collection. We can easily recreate the slected items with text values, but cannot link the ID values to these entries in the Items collection.

    So the question is - how do we restore the Items collection with both Text AND Value to an AutoCompleteBox that were saved previously?

  8. Jørgen Granborg
    Jørgen Granborg avatar
    2 posts
    Member since:
    Sep 2004

    Posted 26 May 2015 in reply to Jørgen Granborg Link to this post

    // We are using a AutoCompleteDataSource to get the AutocompleteItems //
  9. Dimitar
    Dimitar avatar
    2984 posts

    Posted 27 May 2015 Link to this post

    Hi Jorgen,

    Thank you for writing.

    To properly restore the items you need to recreate the same data source and assign it to the autocomplete box. The following example shows how you can save and restore the items using simple csv file. The MyItem class just contains two properties (text and value). The code adds all the items to the autocomplete box when the data source is restored. This is achieved with the Text property: 
    private void radButton1_Click(object sender, EventArgs e)
        selctedItems = radAutoCompleteBox1.Text;
        var csv = new StringBuilder();
        foreach (var item in (BindingList<MyItem>) radAutoCompleteBox1.AutoCompleteDataSource)
            var first = item.Text.ToString();
            var second = item.Value.ToString();
            var newLine = string.Format("{0},{1}{2}", first, second, Environment.NewLine);
        File.WriteAllText("test.csv", csv.ToString());
    private void radButton2_Click(object sender, EventArgs e)
        BindingList<MyItem> data = new BindingList<MyItem>();
        string text = "";
        var reader = new StreamReader(File.OpenRead(@"test.csv"));
        while (!reader.EndOfStream)
            var line = reader.ReadLine();
            var values = line.Split(',');
            data.Add(new MyItem()
                Text = values[0],
                Value = int.Parse(values[1])
            text += values[0] + ";";
        radAutoCompleteBox1.AutoCompleteDataSource = data;
        radAutoCompleteBox1.AutoCompleteDisplayMember = "Text";
        radAutoCompleteBox1.AutoCompleteValueMember = "Value";
        radAutoCompleteBox1.Text = text;

    Could you please check the above code and see if it is suitable for your case? If not could you please specify how this approach is different from your real one?

    I am looking forward to your reply.
    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
Back to Top