$99 VS $1000+. UI Control for ASP.NET AJAX(contains chart and gridview).
DataGridView WinForms Control
Powerful GridView C#.NET control supports data binding to various data sources
Home > WinForms UI Controls > User Manual > Binding to Generic List in C#

GridView Data Binding to Generic Lists in C#.NET

The Kettic DataGridView component is capable of binding to Generic Lists. The GirdView control is able to internally generate grid columns and recognize data for the business object properties which is bound to, so users of the GridView control need not to bind it to a list of simple types. The GridView control can’t be bound to a List of integers for the integer type does not have data property. In this article, we are going through the process of binding GridView C#.NET component to a Generic List.

GridView Data Binding to Lists of Simple Types

The example below demonstrates how to bind the DataGridView C#.NET component to a collection of strings. Because the only string objects property is the Length property, so we will get a grid column which represents the length of strings. The following is the C# code for GridView data binding to list of simple types.

List<string> list = new List<string>();
ketticGridView1.DataSource = list;

GridView Data Binding to Lists of Objects

The Kettic GridView component is capable of binding to Lists of objects that includes support data types. This is achieved by assigning the List to the DataSource property of the DataGriView control. In the example as following, we will define a MyObject C# class which will contains the integer and string property and create an array of MyObject in C# to initialize the array with objects. And then we will assign the array to the DataSource property.

public class MyObject
public MyObject(int myInt, string myString)
_myInt = myInt;
_myString = myString;
private int _myInt;
public int MyInt
get { return _myInt; }
set { _myInt = value; }
private string _myString;
public string MyString
get { return _myString; }
set { _myString = value; }
C# code for GridView data binding to list of simple types

List<MyObject> myList = new List<MyObject>();
myList.Add(new MyObject(1, "Tables"));
myList.Add(new MyObject(2, "Cups"));
myList.Add(new MyObject(3, "Chairs"));
myList.Add(new MyObject(4, "Bottles"));
myList.Add(new MyObject(5, "Spoons"));
ketticGridView1.DataSource = myList;
UI Controlsfor Windows Forms
.NET WinForms UI Overview.NET WinForms UI Features.NET WinForms UI GuideC# WinForms UI DesignVB.NET WinForms UI Design
WinForms UI Controls