Binding a .NET grid control to strongly typed dataset

USAtech
USAtech used Ask the Experts™
on
I have a .net grid control which i need to bind. The grid needs to be populated from a webservice method.

   Dim objWS As New WebMaxServices.WebMaxSoapClient
   dgvResult.DataSource = objWS .RetrieveFromWishlist(1, 1)
   dgvResult.binddata()

I do not see the DataBind method for the windows data grid

I am familiar with how it is done in ASP.net for not the windows form grid.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
kaufmedGlanced up at my screen and thought I had coded the Matrix...  Turns out, I just fell asleep on the keyboard.
Most Valuable Expert 2011
Top Expert 2015

Commented:
There is no DataBind method for the WinForms controls. Assign the DataSource property and set the DisplayMember and ValueMember properties to the field names found in the object returned by your web service call, and you should be set.
kaufmedGlanced up at my screen and thought I had coded the Matrix...  Turns out, I just fell asleep on the keyboard.
Most Valuable Expert 2011
Top Expert 2015

Commented:
Disregard my mention of the DisplayMember and ValueMember. I was apparently thinking of a different control. However, my other comment still stands--in WinForms, you simply need to assign the data source; there is no DataBind method.

e.g.

Screenshot

Author

Commented:
So the following statement should work.

Dim objWS As New WebMaxServices.WebMaxSoapClient
dgvResult.DataSource = objWS .RetrieveFromWishlist(1, 1)
Acronis in Gartner 2019 MQ for datacenter backup

It is an honor to be featured in Gartner 2019 Magic Quadrant for Datacenter Backup and Recovery Solutions. Gartner’s MQ sets a high standard and earning a place on their grid is a great affirmation that Acronis is delivering on our mission to protect all data, apps, and systems.

Glanced up at my screen and thought I had coded the Matrix...  Turns out, I just fell asleep on the keyboard.
Most Valuable Expert 2011
Top Expert 2015
Commented:
Whatever is returned by RetrieveFromWishlist(1,1) should be in a structure similar to what I have in the above screenshot. Basically, when you assign to the DataSource the runtime is going to loop through the properties of that object being bound to and whatever properties are visible/accessible will show up in the grid. If I were to do a List(Of String) instead, then I would get this:

With a Different DataSource
This is because for a String object, the only accessible property is Length. You essentially need a collection of things where the thing has one or more properties you want to display. The runtime will take care of adding them to the grid so long as the are Public properties.

Author

Commented:
The method retrieves the data for the following columns.

ID, TITLE,PRICE,PUBLISHER_NAME,AUTHOR

So if i just specify the datasource, won't is suffice.
4-14-2012-9-36-30-PM.gif
4-14-2012-9-38-32-PM.gif
kaufmedGlanced up at my screen and thought I had coded the Matrix...  Turns out, I just fell asleep on the keyboard.
Most Valuable Expert 2011
Top Expert 2015

Commented:
It's been a while since I've worked with strongly-typed DataSets, but I believe that should be all you need, yes.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial