AutoComplete with WCF

10 posts, 0 answers
  1. David
    David avatar
    7 posts
    Member since:
    Aug 2008

    Posted 09 Apr 2009 Link to this post

    Hi,

    I'm following this Example http://blogs.telerik.com/ValeriHristov/Posts/08-12-04/Auto-complete_ComboBox_with_WCF_Service_and_RadControls_for_Silverlight.aspx and i have got it working up to getting results and filtering the only diffrence is i'm binding to a ObservableCollection of a Class not a string the only problem i'm having now is that when i start doing a search and getting results say Allen i get 3 Allens when there is only one appering in the Drop down no idea why i have looking it over and over here is the XAML

                        <telerikInput:RadComboBox x:Name="ddlUsers" GotFocus="ddlUsers_GotFocus" DisplayMemberPath="Username"   
                                                  ItemsSource="{Binding Users}" Text="{Binding Text, Mode=TwoWay}" 
                                                  IsTextSearchEnabled="False" IsEditable="True" HorizontalAlignment="Left" Margin="24,23,0,8" Width="155"/>  
     

    and the WebService

            private static UserEOList Users  
            {  
                get 
                {  
                    UserEOList user = HostingEnvironment.Cache["Service.Users"as UserEOList;  
     
                    if(user == null)  
                    {  
                        var userList = new UserEOList();  
                        userList.Load();  
                        HostingEnvironment.Cache["Service.Users"] = userList;  
                    }  
                        return user;  
                }  
            }  
     
            [OperationContract]  
            public List<UserEO> SearchUsers(string prefix)  
            {  
                bool empty = string.IsNullOrEmpty(prefix);  
                return (from a in Users  
                        where empty || a.Username.ToLower().StartsWith(prefix.ToLower())  
                        orderby a.Username  
                        select a).Take(10).ToList();  
     
            } 

    And Data Source
     public string Text  
            {  
                get { return text; }  
                set 
                {  
                    if (text != value)  
                    {  
                        text = value;  
                        OnPropertyChanged("Text");  
                        getUsers();  
                    }  
                }  
            }  
     
            private void getUsers()  
            {  
                service.SearchUsersAsync(Text);  
            }  
     
            private void service_SearchUsersCompleted(object sender, SearchUsersCompletedEventArgs e)  
            {  
                if (e.Error == null)  
                {  
                    var empty = string.IsNullOrEmpty(Text);  
                    for (var i = Users.Count - 1; i >= 0; i--)  
                    {  
                        if (empty || !Users[i].Username.ToLower().Contains(Text.ToLower()))  
                        {  
                            Users.RemoveAt(i);  
                        }  
                    }  
     
                    foreach (var user in e.Result)  
                    {  
                        if (!Users.Contains(user))  
                            Users.Add(user);  
                    }  
                }  
            } 

    Please Help
  2. Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 09 Apr 2009 Link to this post

    Hello David,

    As far as I understand, the problem is that you cannot have duplicate items in the combo box. This is because of the following code (it is at the end of your third code snippet):
    foreach (var user in e.Result)

        if (!Users.Contains(user)) 
            Users.Add(user);
    }

    You could change it like this:
    foreach (var user in e.Result)

            Users.Add(user);
    }

    and the combo box will be filled with the duplicate items.

    Greetings,
    Valeri Hristov
    the Telerik team

    Check out Telerik Trainer , the state of the art learning tool for Telerik products.
  3. David
    David avatar
    7 posts
    Member since:
    Aug 2008

    Posted 09 Apr 2009 Link to this post

    Hi,

    I don't want Duplicates when i start typeing Allen i just want it to filter the List to Allen but the combo box is doing this

    ComboBox: All
    Result : Allen
    Result: Allen
    Result: Allen

    if i add the e in allen i get
    ComboBox: Alle
    Result : Allen
    Result: Allen
    Result: Allen
    Result: Allen

    it seems to add a new row into the combo box but not into the List (not wanted) what i would like is

    ComboBox: All
    Result : Allen

    not each time i enter the name get more then one result
  4. Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 10 Apr 2009 Link to this post

    Hi David,

    Could you please, send me your project? I will check it out and will post here what's wrong. You should open a support ticket to add attachments.

    Sincerely yours,
    Valeri Hristov
    the Telerik team

    Check out Telerik Trainer , the state of the art learning tool for Telerik products.
  5. David
    David avatar
    21 posts
    Member since:
    Apr 2009

    Posted 10 Apr 2009 Link to this post

    I won't be able to send the project but what i'll do is make a project that should replicate it hopefully

    David
  6. Charles
    Charles avatar
    75 posts
    Member since:
    Aug 2008

    Posted 02 Mar 2010 Link to this post

    I just wanted to request something here because it is more recent than the blog posting describing how to accomplish autocompletion with a large set of data. (The one that the original poster refers to.)

    I've been able to implement this solution to provide an autocomplete search for user ids. It works fine except for a single annoying glitch. As the user types, the matching user ids are displayed in the dropdown portion of the combo box. However, if the user sees a match, perhaps halfway down the list and chooses to use the arrow keys on the keyboard to attempt to select it instead of completing the user id by typing, the combo box forces a selection of the nearest match. In other words, the user has no choice except to keep typing or to use the mouse (which does allow a choice further down in the list.)

    Is there any way to work around this behavior?
  7. Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 03 Mar 2010 Link to this post

    Hi Charles,

    The latest internal build of RadControls for Silverlight should fix the problem (version 2009.3.1426.1030):
    http://www.telerik.com/account/downloads/internal-builds.aspx

    Best wishes,
    Valeri Hristov
    the Telerik team

    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 Public Issue Tracking system and vote to affect the priority of the items.


    All the best,
    Valeri Hristov
    the Telerik team

    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 Public Issue Tracking system and vote to affect the priority of the items.
  8. Charles
    Charles avatar
    75 posts
    Member since:
    Aug 2008

    Posted 03 Mar 2010 Link to this post

    Thanks for the quick reply.

    I downloaded the latest internal build (Silverlight 3 version) and tried again. Replaced all references just to make sure I had latest DLLs. I still have the same problem. As soon as the user stops typing and tries to use the arrow keys on the keyboard to navigate through the dropdown, the closest match is selected into the text portion of the combobox and no other navigation is possible. (Using the mouse is an option...that works, but might be awkward for some users who want to keep their hands on the keyboard.)

    Perhaps there's a property setting on the combobox that would prevent this behavior? (I pretty much have the same settings as in your blog.

                <radInput:RadComboBox x:Name="rcboUserSearch" Grid.Row="1" Grid.Column="1" Width="300" Margin="5,0,0,0" HorizontalAlignment="Left" 
                                  IsEditable="True" ItemsSource="{Binding Users}" Text="{Binding Text, Mode=TwoWay}" 
                                  IsTextSearchEnabled="False" GotFocus="rcboUserSearch_GotFocus">  
                </radInput:RadComboBox> 
  9. Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 04 Mar 2010 Link to this post

    Hi Charles,

    Please, find attached the upgraded sample from the blog post. The archive also contains the assemblies from internal build 1426 and it seems to work as expected. Please, let me know if you experience additional problems.

    Kind regards,
    Valeri Hristov
    the Telerik team

    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 Public Issue Tracking system and vote to affect the priority of the items.
  10. Charles
    Charles avatar
    75 posts
    Member since:
    Aug 2008

    Posted 04 Mar 2010 Link to this post

    I believe the addition of the two properties "CanAutocompleteSelectItems" and "CanKeyboardNavigationSelectItems" made it all work as advertised. Once I put those into my project (as set up in the combobox style settings in your example) everything worked as expected.

    Thanks again for the quick replies.
Back to Top