locked
Silverlight c# populating a combo box based on a query RRS feed

  • Question

  • I am looking to provide a form whereby the user can select a quote from a combo box, so far I have the following code:

            // Retrieves quotes found.
            private void BeginPopulateQuotes()
            {
                //Retrieve 50 quotes
                int numberToRetrieve = 50;
                DataServiceQuery<Quote> quotes = (DataServiceQuery<Quote>)this._context.QuoteSet.Take<Quote>(numberToRetrieve);
                try
                {
                    quotes.BeginExecute(OnRetrieveQuotesComplete, quotes);
                }
                catch (DataServiceQueryException dsqe)
                {
                    _syncContext.Send(new SendOrPostCallback(showErrorDetails), dsqe);
                }
            }
    
            // Displays the names from any Quotes retrieved.
            private void OnRetrieveQuotesComplete(IAsyncResult result)
            {
                //Retrieve the query that was 
                DataServiceQuery<Quote> results = result.AsyncState as DataServiceQuery<Quote>;
    
                try
                {
                    //Create a collection of Quotes and set it equal to the query result
                    ObservableCollection<Quote> _quote = new DataServiceCollection<Quote>(results.EndExecute(result));
    
                    //For each Account found, display the Account Name
                    foreach (Quote quote in _quote)
                    {
                        cmb_Quotes.Items.Add(quote.Name);
                    }
                }
                catch (SystemException se)
                {
                    _syncContext.Send(new SendOrPostCallback(showErrorDetails), se);
                }
            }

    However I want the query to select all quotes for accounts where their names contain text in a text box, this allows the user to pre-filter the selected quotes, I am lost as to how to do this, anybody help?

    e.g. user puts "A" in a text box then on exit the combox box is populated with all quote numbers that belong to accounts beginning with A.

    regards,

    Matt

    Wednesday, October 9, 2013 2:20 PM

All replies

  • Hi,

    In Odata you can achieve your requirement using below operators.

    startswith  ---  this._context.QuoteSet?$filter=startswith(Name, 'a')  -- This will return the records where Name starts with A.

    substringof-- this._context.QuoteSet?$filter=substringof('store',Name) - This will check if the name contains specified word.

    endswith--- this._context.QuoteSet?$filter=endswith(Name, '(sample)') -- his will return the records where Name Ends with A.

    http://msdn.microsoft.com/en-us/library/gg309461.aspx

    You can design your query using Query Designer.

    http://crm2011odatatool.codeplex.com/

    HTH!

    Thanks!

    • Proposed as answer by Kalim Khan Wednesday, October 9, 2013 4:29 PM
    Wednesday, October 9, 2013 4:23 PM
  • Thanks for this, but am a little lost at the moment...

    At what point in my code do I put this, here?

    DataServiceQuery<Quote> quotes = (DataServiceQuery<Quote>)this._context.QuoteSet?$filter=startswith(Name, 'a').Take<Quote>(numberToRetrieve);

    Am new to this, but struggling to find easy to follow examples.

    regards,

    matt

    Thursday, October 10, 2013 8:49 AM
  • Guess I am really looking for best advice on how to get started with querying Dynamics crm data for a silverlight application that I am writing.

    Anybody help?

    regards,

    Matt

    Thursday, October 10, 2013 10:29 AM