Currently working in .NET Framework 4
Create your class to the hold the data you want to bind to.
namespace WebOrders
{
public class OrderListItem
{
[DisplayName(@"WebOrderID")]
public string WebOrderId { get; set; }
[DisplayName(@"ID")]
public string Id { get; set; }
public string Location { get; set; }
public OrderListItem()
{
}
public OrderListItem(string weborderId, string id, string location)
{
WebOrderId = weborderId;
Location = location;
Id = id;
}
}
}
Then create a BindingSource from the tools menu.
BindingSource.DataSource should be the class name including the namespace. In this case the DataSource for my project is WebOrders.OrderListItem
The DataSource for the DataGridView will then be the name of the BindingSource. So in this case it will be bindingSourceOrderList
As soon as you bind to the bindingsource the columns should be created and the display name will be used as the column header text if the displayname is not filled in then the name is used.
To add data just use:
bindingSourceOrderList.Add(new OrderListItem(order.ID, obj.BatchId, obj.Location));