Saturday, 22 December 2012 15:54

how to display ArrayList content in DtataGrid

Written by 
Rate this item
(0 votes)

we all know well that the DataGrid is used for database work.we
can use DataGrid contorl to show data from database tables.
but it's that the new version of the DataGrid control in the c#
language and Vb.net is able to show any other objects
of classes which implements IList interface.

so we are not able to show the content of any HashTable because it
doesn't implement that IList interface

A Example:
public class AddressList{
protected string strName;
protected string strPhone;
protected string strAddress;
AddressList()
{
}
public string HeaderName
{ get
{return strName;}
set
{strName = value;}
//other properties
}}

in the Class of Form Create ArrayList and DataGrid as follows-
private ArrayList AdrsList = new ArrayList(15);
private AddressList address; //this address will be stored

now let us add some data in the ArrayList and show that in the
DataGrid as follows -
address = new AddressList();
address.HeaderName = txtName.Text;
address.Phone = phoneBox.Text;
address.Address = addressBox.Text;

AdrsList.Add(address);

dataGridAdrsBook.DataSource = null;
dataGridAdrsBook.Refresh();

// Set the DataGrid DataSource to our ArrayList
// then refresh it
dataGridAdrsBook.DataSource = AdrsList;
dGridAdrsBook.Refresh();

Read 1500 times
Super User

Email This email address is being protected from spambots. You need JavaScript enabled to view it.
Login to post comments