locked
CRM 2011 - silverlight combobox display stored value out of CRM RRS feed

  • Question

  • I have 2 combo boxes.  For each combo box i display values based on selected values in other combo boxes.  I'm able to save the results into the CRM from the combo boxes however i'm not able to display them back.

    Below is my code that pulls the values out of CRM which sets the value of my first combo box which then fires the on change event of that combo box to populate values in 2nd combo box.

    How can i display the value in my combo box out of CRM?

     private void GetExistingBuilding(string _quid)
            {
                string _filter = "";
                _filter += "new_QuoteId eq ('" + _quid + "')";
                DataServiceQuery<new_building> _query = (DataServiceQuery<new_building>)_context.new_buildingSet
                    .AddQueryOption("$filter", _filter);
                _query.BeginExecute(RetrieveBuildingDetails, _query);
            }
    
            private void RetrieveBuildingDetails(IAsyncResult result)
            {
                try
                {
                    DataServiceQuery<new_building> results = result.AsyncState as DataServiceQuery<new_building>;
                    ObservableCollection<new_building> retrievedBuilding = new DataServiceCollection<new_building>(results.EndExecute(result));
    
                    if (retrievedBuilding[0].new_buildingId != null)
                    {
                        BuildingId = retrievedBuilding[0].new_buildingId;
                    }
                                                                  
                    Building b = new Building(_quid, retrievedBuilding[0].new_Series, retrievedBuilding[0].new_ModelName
                        , (bool)retrievedBuilding[0].new_10Crimp, retrievedBuilding[0].new_Gauge, (decimal)retrievedBuilding[0].new_Freight
                        , (int)retrievedBuilding[0].new_Fedex, (decimal)retrievedBuilding[0].new_PinCharge, (decimal)retrievedBuilding[0].new_Insulation
                        , (decimal)retrievedBuilding[0].new_PriceOffered);                                
                 
                    cboSeries.DataContext = b.Series; //This displays the value
                    cboModel.DataContext = b.ModelNm; // This is my 2nd combo box that does not display anything
                                         
                }
                catch (SystemException se)
                {
                    _syncContext.Send(new SendOrPostCallback(showErrorDetails), se);
                }
            }
    
    //HERE IS THE EVENT THAT IS TRIGGERED WHEN I ASSIGN A VALUE TO cboSeries
    
    private void cboSeries_SelectionChanged(object sender, SelectionChangedEventArgs e)
            {
                string _tempTitle = "";
                cboModel.Items.Clear();
                cboGauge.Items.Clear();
                
                if (cboSeries.SelectedItem != null)
                {
                    string selectedValue = (string)cboSeries.SelectedValue;
                    string filter = "";
                    //   DataServiceQuery<Subject> query = (DataServiceQuery<Subject>)_context.SubjectSet.Where<Subject>(s => s.Title == selectedValue);
                    //   query.BeginExecute(RetriveSubjectGuid, query);
    
    
                    filter += "subject_products/Title eq ('" + selectedValue + "') ";
                    DataServiceQuery<Product> query = (DataServiceQuery<Product>)_context.ProductSet
                        .AddQueryOption("$top", 1000)
                        //.AddQueryOption("$select", "Name")
                        .AddQueryOption("$filter", filter);
    
                    //query.BeginExecute(RetriveModels, query);
    
                    query.BeginExecute(ProcessPages<Product>, new PagingContext<Product>()
                    {                    
                        ServiceContext = _context,
                        Query = query,
                        PageProcessor = delegate(DataServiceCollection<Product> results)
                        {
                            
                            try
                            {                           
                                if (null == ProductCollection)
                                {
                                    ProductCollection = new DataServiceCollection<Product>(_context);                                
                                    ProductCollection.Load(results);
                                    
                                }
                                else
                                {
                                    for (int i = 0; i < results.Count; i++)
                                    {
                                        if (_tempTitle != results[i].Name)
                                        {
                                            if ((bool)ch10inchCrimp.IsChecked)
                                            {
                                                if (results[i].new_CrimpSize == 10)
                                                {
                                                    cboModel.Items.Add(results[i].Name);
                                                    _tempTitle = results[i].Name;
                                                }
                                            }
                                            else
                                            {
                                                cboModel.Items.Add(results[i].Name);
                                                _tempTitle = results[i].Name;
                                            }
                                        }
                                    }
                                }
                                
                            }    
                            
                            catch (Exception ex)
                            {
                                _syncContext.Send(new SendOrPostCallback(showErrorDetails), ex);
                            }
    
                            return true;
                        }
                    });
    
                }
    
            }
    

    Please let me know if I'm doing something wrong.  This has been bugging me for over a week now.

     

     


    • Edited by FutureSteel Monday, September 19, 2011 7:23 PM
    Monday, September 19, 2011 7:23 PM

Answers

  • i figure it out Amreek.

    What i did was check if the combo box count > 0, then it assigned a value to it.  Worked out great. 

     

     

     

    • Marked as answer by FutureSteel Tuesday, September 20, 2011 2:59 PM
    Tuesday, September 20, 2011 1:18 PM

All replies

  • I can't see a problem with the cboModel.Items.Add

    Can you verify if the code is going into the loop (for (int i = 0; i < results.Count; i++))?

    I hope this helps.



    Amreek singh Senior CRM Consultant CDC Praxa Sydney,Australia http://mscrmshop.blogspot.com/
    • Edited by Amreek Singh Tuesday, September 20, 2011 4:19 AM
    • Proposed as answer by Amreek Singh Tuesday, September 20, 2011 1:29 PM
    Tuesday, September 20, 2011 4:18 AM
  • Amreek,

    Yes, the code runs through the loop.  However, i have to load more than 50 records so the page processor is called multiple times.  Is there a way to determine when the page processor is finished loading, then populate my combo box? 

    Also, when i retrieve the values, it puts a "\" at the end.  It retrieves values that are like this 16' x 12'-50", 20' x 20' ... etc.  It always puts a "\", could that be a problem?

    Is there there a code example where maybe i can search for a value in the combo box and display it?

    Tuesday, September 20, 2011 1:03 PM
  • i figure it out Amreek.

    What i did was check if the combo box count > 0, then it assigned a value to it.  Worked out great. 

     

     

     

    • Marked as answer by FutureSteel Tuesday, September 20, 2011 2:59 PM
    Tuesday, September 20, 2011 1:18 PM
  • That's good.
    Amreek singh Senior CRM Consultant CDC Praxa Sydney,Australia http://mscrmshop.blogspot.com/
    Tuesday, September 20, 2011 1:29 PM