I was able to accomplish this in the code behind but I was wondering if there is away to do it on the designer view.
ultraGrid1.DataSource = UserBLL.GetList(); ultraGrid1.DataBind();
I'm a web developer and I was looking for the equivalent of the ObjectDataSource control, so I can use the designer to bind the grid to a business logic layer class.
Thanks.
Unfortuantely there is no equivalent of an ObjectDataSource for WinForms, so I do not think that there is any way to do this at design-time. The grid needs to have the structure provided to it by an object, and there is no way, at design-time, to do this. Perhaps you can make a design-time instance of your list, or make a class that implements IListSource in order to provide design-time binding. Alternatively, depending on what you need to do at design-time (i.e. if you don't need the column DataTypes to match), you could just define the schema through the grid's designer and bind at run-time.
-Matt
Hey Matt, thanks for your quick reply,
could you please explain this a little further? :
Matt Snyder"]Perhaps you can make a design-time instance of your list, or make a class that implements IListSource in order to provide design-time binding. Alternatively, depending on what you need to do at design-time (i.e. if you don't need the column DataTypes to match), you could just define the schema through the grid's designer and bind at run-time.
Well, as for the IListSource aspect, you would have to implement that interface yourself on some class and instantiate that class at design-time, at which point you could bind the grid to it. This wouldn't be extremely time-consuming, but it's not really trivial either, so I wouldn't recommend doing it unless you have a great need for doing design-time work (especially in multiple different forms). If you look at the DataSet class in the Reflector tool, you can see how they implement IListSource. There are likely other examples online.
As for your other option, open the grid designer and select the "Manually Define a Schema" option for the DataSource section. You can elect to not bind anything to the grid at design-time, so this will allow you to define the various columns that will exist in the grid so you can set various properties on the, set a layout, etc. The downside to this is that the DataType of the columns cannot be set at design-time because they will be determined by the DataSource at run-time, so if you need to do design-work specifically based on the DataType, this isn't a good approach (though I can't think of any particular situations where this would be a major drawback).
The reason why I was trying to bind the grid on design time is to generate the columns automatically so I could save some time on typing.
So I added a BindingSource control and set the DataSource property to "UserList" :
using System;using System.Collections.Generic; /// <summary> /// The UserList class is designed to work with lists of instances of user. /// </summary> public class UserList : List<user> { public UserList() {} }
and in the code behind I do:
Thanks for your help !!!!!!!!
Wow, a pretty glaring oversight on my part that it was that simple. Glad it worked out.