Populating a listbox in C# using Webservices

akerstiens
Member Posts: 15
I am almost embarrassed to ask this question, but seeing how I have been trying one thing after another in Visual Studio, I thought I would ask. I am developing a Windows Form using C# where I am trying to populate a list_box with items it receives from a readmultiple webservice call.
I cannot seem to find a good code example for this in a Windows Form setting.
Thank you all in advance for your help.
I did find the below example for VB however not for c# :-)
Dim ws As New Mywebservice.Customer_Binding
ws.UseDefaultCredentials = True
ws.Url = "http://localhost:7047/DynamicsNAV/WS/CRONUS_International_Ltd/Page/Customer"
Dim Cust(100) As Mywebservice.Customer
Dim wsFields As New Mywebservice.Customer_Fields
Dim wsfilter(1) As Mywebservice.Customer_Filter
wsfilter(1).Field = wsFields.Name
wsfilter(1).Criteria = "J*"
Cust = ws.ReadMultiple(wsfilter, "", 0)
For Counter = LBound(Cust) To UBound(Cust)
Me.ListBox1.Items.Add(Counter & ": " + Cust(Counter).No & "-> " & Cust(Counter).Name)
Next Counter
I cannot seem to find a good code example for this in a Windows Form setting.
Thank you all in advance for your help.
I did find the below example for VB however not for c# :-)
Dim ws As New Mywebservice.Customer_Binding
ws.UseDefaultCredentials = True
ws.Url = "http://localhost:7047/DynamicsNAV/WS/CRONUS_International_Ltd/Page/Customer"
Dim Cust(100) As Mywebservice.Customer
Dim wsFields As New Mywebservice.Customer_Fields
Dim wsfilter(1) As Mywebservice.Customer_Filter
wsfilter(1).Field = wsFields.Name
wsfilter(1).Criteria = "J*"
Cust = ws.ReadMultiple(wsfilter, "", 0)
For Counter = LBound(Cust) To UBound(Cust)
Me.ListBox1.Items.Add(Counter & ": " + Cust(Counter).No & "-> " & Cust(Counter).Name)
Next Counter
0
Comments
-
Thats a good question.
Well are you using any ajax or special tools to populate your list box with web services? Or is it a just a list box?0 -
Web Services :-)0
-
The C# code is very simple...
First of all I create a Web Reference (Add Service Reference -> Advanced -> Add Web Reference) to the customer page and call it CustomerPageRef, I also added a using statement and then the C# code would be:var service = new Customer_Service(); service.UseDefaultCredentials = true; var filter = new Customer_Filter(); filter.Field = Customer_Fields.Name; filter.Criteria = "J*"; var filters = new Customer_Filter[] { filter }; Customer[] customers = service.ReadMultiple(filters, null, 0); foreach (Customer customer in customers) this.listBox1.Items.Add(customer.Name);
good luckFreddy Kristiansen
Group Program Manager, Client
Microsoft Dynamics NAV
http://blogs.msdn.com/freddyk
The information in this post is provided "AS IS" with no warranties, and confers no rights. This post does not represent the thoughts, intentions, plans or strategies of my employer. It is solely my opinion.0 -
Or you can take the result of the webservice as DataBinding source for your listbox:
var service = new Customer_Service(); service.UseDefaultCredentials = true; var filter = new Customer_Filter(); filter.Field = Customer_Fields.Name; filter.Criteria = "J*"; var filters = new Customer_Filter[] { filter }; Customer[] customers = service.ReadMultiple(filters, null, 0); this.listBox1.DataSource = customers; this.listBox1.DisplayMember = Customer_Service.Customer_Fields.Name.ToString();
0 -
Being a VS novice, I also had the problem.
I added a data grid control to Form1 bound to the customer page web service.
If I added the Name field to the datagrid, I would get errors. The error was in standard code:
this.Name = "Form1";
It appears that having a field Name conflicted with the property of the form. VS was confused.
The errors in VS were:
Error 1 Cannot implicitly convert type 'string' to 'System.Windows.Forms.DataGridViewTextBoxColumn'
Warning 2 'Customer_Lookup.Form1.Name' hides inherited member 'System.Windows.Forms.Control.Name'. Use the new keyword if hiding was intended.
When I remove the Name field from the Datagrid, no errors.
So, to fix this, in the Edit Columns dialog, I selected the Name field, then changed the (Name) property to CustName. Now all is good and the form runs.
Hopefully, this will help someone get around the issue of using NAV "Name" fields in VS."There are only two truly infinite things: the universe and stupidity. And I am unsure about the universe." - Albert Einstein
Corollary- Build and idiot proof system and nature will build a better idiot.0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions