C# Store app. Convert NAV data to ObservableCollection. RRS feed

  • Question

  • Hi,

    Currently i get data from Microsoft Dynamics Nav into my store app. The problem is: I can't convert this data to an ObservableCollection so i can view the data on my screen. 

            private static NAVDataConnection _sampleDataSource = new NAVDataConnection();
            private ObservableCollection<ProductGroup> _groups = new ObservableCollection<ProductGroup>();
            public ObservableCollection<ProductGroup> Groups
                get { return this._groups; }
                set { this._groups = value; }
           public async Task<IEnumerable<ProductGroup>> GetGroupsAsync()
                 await _sampleDataSource.getNAVCategorie(); 
                return _sampleDataSource.Groups;
      public async Task getNAVCategorie()
                Groups = new ObservableCollection<ProductGroup>();
                BasicHttpBinding binding = new BasicHttpBinding { };
                binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
                binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
                EndpointAddress epa = new EndpointAddress("Service here !!");
                AppService_PortClient ws = new AppService_PortClient(binding, epa);
                ws.ClientCredentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials;
                ws.ClientCredentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Delegation;
                ItemCategory ic = new ItemCategory();
                GetItemCategory catrequest = new GetItemCategory(ic);
                GetItemCategory_Result catresult = await ws.GetItemCategoryAsync(catrequest);

    As you can see i have an ObservableColelction<ProductGroup> (so i don't know if its possible to do it like that or that i need to use a different ObservableCollection) now i want either to convert the results i get from the NAV datacall to convert to a productgroup and then in an ObservableColletion. Or just place it directly in an ObservableCollection. I cannot use a foreach loop because the result does not contain a public definition for "GetEnumerator". 

    Does anyone know how to bind the nav data to my screen using an ObservableCollection?

    Thanks in advance.

    • Edited by Proliges Friday, May 9, 2014 11:51 AM
    Friday, May 9, 2014 11:50 AM


  • You'll need to explain how the returned data is formatted.  You'll probably need to break the data into chunks and then place each part into it's own object, then add that to an observable collection.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Friday, May 9, 2014 12:08 PM