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

How can a popular SuggestionsSource from webservices?

4 Answers 95 Views
AutocompleteBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Dario
Top achievements
Rank 1
Dario asked on 19 Dec 2011, 10:14 AM
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?

4 Answers, 1 is accepted

Sort by
0
Deyan
Telerik team
answered on 20 Dec 2011, 08:55 AM
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 >>

0
Dario
Top achievements
Rank 1
answered on 20 Dec 2011, 09:47 AM
However I was able to implement a functional solution.
Soon the place code.
0
Deyan
Telerik team
answered on 20 Dec 2011, 10:38 AM
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 >>

0
Dario
Top achievements
Rank 1
answered on 20 Dec 2011, 02:33 PM
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!
Tags
AutocompleteBox
Asked by
Dario
Top achievements
Rank 1
Answers by
Deyan
Telerik team
Dario
Top achievements
Rank 1
Share this question
or