How can a popular SuggestionsSource from webservices?

5 posts, 0 answers
  1. Dario
    Dario avatar
    11 posts
    Member since:
    Oct 2012

    Posted 19 Dec 2011 Link to this post

    How can a popular SuggestionsSource from webservices?
    I have tried in various ways, but the control must lose focus or rewrite to see tips.

    I tried something like that
    <telerikInput:RadAutoCompleteBox AutoCompletePopupDisplayMode="BelowTextBox" FilterDelay="0:0:0.350" x:Name="RACBSearch" Grid.Row="1" AutoCompleteMode="Contains" TextChanged="RACBSearch_TextChanged" >
                    <telerikInput:RadAutoCompleteBox.SuggestionItemTemplate>
                        <DataTemplate>
                            <Grid Margin="-12, -3, 0, -3">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition/>
                                </Grid.ColumnDefinitions>
                                
                                <Grid Grid.Column="1">
                                    <Grid.RowDefinitions>
                                        <RowDefinition/>
                                        <RowDefinition/>
                                    </Grid.RowDefinitions>
                                    <TextBlock Text="{Binding TITOLO}" FontSize="{StaticResource PhoneFontSizeMedium}"/>
                                    <TextBlock Text="{Binding EDITORE}" Grid.Row="1" FontSize="{StaticResource PhoneFontSizeSmall}" Foreground="#3BB23B"/>
                                </Grid>
                            </Grid>
                        </DataTemplate>
                    </telerikInput:RadAutoCompleteBox.SuggestionItemTemplate>
                </telerikInput:RadAutoCompleteBox>

    private void RACBSearch_TextChanged(object sender, TextChangedEventArgs e)
            {
                RadAutoCompleteBox s = (RadAutoCompleteBox) sender;
                if (s.Text.Count() == 3 && !_performanceProgressBar.IsIndeterminate)
                {
                    //s.IsEnabled = false;
                    _performanceProgressBar.IsIndeterminate = true;
                    string url = string.Format(application.UrlOfServicesAPP + "/Search?T='{0}'", s.Text);
                    var request = HttpWebRequest.Create(url) as HttpWebRequest;
                    request.Accept = "application/json";
                    request.BeginGetResponse(Ricerca_Callback, request);
                }
            }
     
            private void Ricerca_Callback(IAsyncResult result)
            {
                try
                {
                    var request = result.AsyncState as HttpWebRequest;
                    var response = request.EndGetResponse(result);
                    var deserializer = new DataContractJsonSerializer(typeof(APPData));
                    var data = deserializer.ReadObject(response.GetResponseStream()) as APPData;
                    if (data != null)
                    {
                        var a = from x in data.d
                                select new APPLittle()
                                           {
                                               APPID = x.APPID,
                                               EDITORE = x.EDITORE,
                                               TITOLO = x.TITOLO
                                           };
                        if (AppLittle == null)
                        {
                            AppLittle = a;
                        }
                        else
                        {
                            AppLittle.Concat(a);
                        }
                        this.Dispatcher.BeginInvoke(() =>
                                                    {
                                                        RACBSearch.SuggestionsSource = a;
                                                    });
        
                    }
                }
                catch (Exception e)
                {
                    this.Dispatcher.BeginInvoke(() =>
                    {
                        MessageBoxResult mbResult = MessageBox.Show("There is a problem in the connection.", "Connection Problem", MessageBoxButton.OK);
                    });
                }
                finally
                {
                    this.Dispatcher.BeginInvoke(() =>
                                                    {
                                                        //RACBSearch.IsEnabled = true;
                                                        _performanceProgressBar.IsIndeterminate = false;
                                                        //RACBSearch.compl;
                                                    });
                }
     
            }


    can you help me?
  2. Deyan
    Admin
    Deyan avatar
    2038 posts

    Posted 20 Dec 2011 Link to this post

    Hello Dario,

    Thanks for contacting us and for your question.

    Currently, RadAutoCompleteBox does not support scenarios in which data is fetched from a WebService. It only supports scenarios where the items available for filtering are prefetched and loaded as a SuggestionsSource.

    I would like to inform you that we already have plans to extend the feature-set of RadAutoCompleteBox and add support for connected scenarios. This will most probably be available for Q1 2012 which is due to February (two months from now).

    Do not hesitate to get back to us in case you have further questions or need assistance.

    Best wishes,
    Deyan
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. DevCraft banner
  4. Dario
    Dario avatar
    11 posts
    Member since:
    Oct 2012

    Posted 20 Dec 2011 Link to this post

    However I was able to implement a functional solution.
    Soon the place code.
  5. Deyan
    Admin
    Deyan avatar
    2038 posts

    Posted 20 Dec 2011 Link to this post

    Hello Dario,

    Thanks for writing back.

    If your solution works as expected, it will be great if you share it here on the forums so that other users can take a look at it as well and use it.

    Thanks for your time.

    Kind regards,
    Deyan
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  6. Dario
    Dario avatar
    11 posts
    Member since:
    Oct 2012

    Posted 20 Dec 2011 Link to this post

    this is a good soluction like minimumpopulatedelay=3

    <telerikInput:RadAutoCompleteBox  AutoCompletePopupDisplayMode="AboveTextBox" FilterDelay="0:0:0.250" x:Name="RACBSearch" Grid.Row="4" AutoCompleteMode="Contains" TextChanged="RACBSearch_TextChanged" Margin="0,150,0,0">
     
                </telerikInput:RadAutoCompleteBox>

    add TextChanged="RACBSearch_TextChanged"

    public string Ricercato;
     
    private void RACBSearch_TextChanged(object sender, TextChangedEventArgs e)
            {
                RadAutoCompleteBox s = (RadAutoCompleteBox) sender;
                if (s.Text.Count() < 3)
                {
                    try
                    {
                        LayoutRoot.Children.OfType<Canvas>().FirstOrDefault().Visibility =
                            System.Windows.Visibility.Collapsed;
                    }
                    catch (Exception)
                    {
                    }
                }
                else
                {
                    try
                    {
                        LayoutRoot.Children.OfType<Canvas>().FirstOrDefault().Visibility =
                            System.Windows.Visibility.Visible;
                    }
                    catch (Exception)
                    {
                    }
                }
                if (s.Text.Count() == 3 && !_performanceProgressBar.IsIndeterminate )
                {
                    if (s.Text != Ricercato)
                    {
                        Ricercato = s.Text;
                        s.IsEnabled = false;
                        s.Text = "Loading";
                        _performanceProgressBar.IsIndeterminate = true;
                        string url = string.Format(application.UrlOfServicesAPP + "/Search?T='{0}'", Ricercato);
                        var request = HttpWebRequest.Create(url) as HttpWebRequest;
                        request.Accept = "application/json";
                        request.BeginGetResponse(Ricerca_Callback, request);
                    }
                }
            }
    LayoutRoot.Children.OfType<Canvas>().FirstOrDefault().Visibility = System.Windows.Visibility.Collapsed;
    is important to hide the popup of Suggestions

    private void Ricerca_Callback(IAsyncResult result)
            {
                try
                {
                    var request = result.AsyncState as HttpWebRequest;
                    var response = request.EndGetResponse(result);
                    var deserializer = new DataContractJsonSerializer(typeof(APPData));
                    var data = deserializer.ReadObject(response.GetResponseStream()) as APPData;
                    if (data != null)
                    {
                        var a = from x in data.d
                                select new APPLittle()
                                           {
                                               ........
                                           };
                        if (a != null)
                        {
                            a = a.Distinct();
                        }
                        //AppLittle = a;
                        this.Dispatcher.BeginInvoke(() =>
                                                    {
                                                        RACBSearch.SuggestionsSource = a;
                                                    });
                    }
                }
                catch (Exception e)
                {
                    this.Dispatcher.BeginInvoke(() =>
                    {
                        MessageBoxResult mbResult = MessageBox.Show("There is a problem in the connection.", "Connection Problem", MessageBoxButton.OK);
                    });
                }
                finally
                {
                    this.Dispatcher.BeginInvoke(() =>
                                                    {
                                                        RACBSearch.IsEnabled = true;
                                                        _performanceProgressBar.IsIndeterminate = false;
                                                        RACBSearch.Text = Ricercato;
                                                        RACBSearch.Focus();
                                                        RACBSearch.Select(3,1);
                                                    });
                }


    previously
    RACBSearch.IsEnabled = false;
    after
    RACBSearch.IsEnabled = true;
    _performanceProgressBar.IsIndeterminate = false;
    RACBSearch.Text = Ricercato;
    RACBSearch.Focus();
    RACBSearch.Select(3,1);

    the focus and select can possible to continue typing.

    I hope there was of help and trust in some Telerik Points!
Back to Top
DevCraft banner