Introduction
In this article, I will discuss how to bind objects such as an ArrayList to a DataGrid control using C# and ADO.NET.
Binding an ArrayList
If you create an ArrayList and bind it to the DataGrid control, DataGrid does not display the contents. For example, the following code creates an ArrayList objects, add items to it, and binds it to the DataGrid:
ArrayList list =
The Solution
The solution of the problem is to create a class that exposes an integer as its property. Then you create an ArrayList and bind it to the DataGrid. For example, the following code creates an ArrayList of MyClass object, which takes one value as constructor parameter. Here MyClasss exposes this value as an int property.
Here is a class with integer and string properties.
public
Where StringMember, IntMember, and NullMember are three properties of the object.
See the attached code for more details.
Summary
In this article, you learned how to take advantage of DataGrid binding feature to display the contents of an array of objects.