aha - this is what I had missed.
I was using public fields (sorry - I missed the public off my code snippet).
when I put in some property accessors it worked.
Unfortunately it will be a bit of a PITA as the objects I'm trying to
display don't have accessors so I will have to wrap them in another object
:-(
In the meantime I have also discovered template columns which I think may
allow me to access the properties directly. So hopefully I have a couple of
workable options.
Thanks for your help
Andy
"Bharat Biyani" <Bh**********@d iscussions.micr osoft.com> wrote in message
news:FA******** *************** ***********@mic rosoft.com...
Hi Andy,
To make the object bindable to the datagrid u will need to expose the
variables of the class as the properties of the Person object. Then u will
be able to bind the properties. Here is a code fragment which will help u
make things clearer.
Set the AutoGenerateCol umns property of datagrid to false.
Person[] p =new Person[2];
p[0]=new Person("John"," Wright");
p[1]=new Person("John"," abraham");
DataGrid1.DataS ource=p;
BoundColumn bc=new BoundColumn();
bc.DataField="F Name";
bc.HeaderText=" First Name";
DataGrid1.Colum ns.Add(bc);
bc=new BoundColumn();
bc.DataField="L Name";
bc.HeaderText=" Last Name";
DataGrid1.Colum ns.Add(bc);
DataGrid1.DataB ind();
---
Bharat Biyani (bs*@orcim.com)
http://www.orcim.com
"Andy Fish" wrote:
Hi,
I have some data which is stored as an array (or possibly an arraylist)
of identically typed objects, each of which has certain public properties.
I want to display these in a datagrid control.
According to the documentation, the datasource of a datagrid can be
anything which implements IEnumerable (which includes array and arraylist).
However, every example I've seen for datagrid uses a DataTable to store the data.
is there any way to achieve this?
here's a sample code snippet which doesn't work but I hope it
illustrates what I'm trying to do:
class person {
string firstname;
string lastname;
}
person[] people = GetListOfPeople ();
DataGrid.dataSo urce = people;
DataGrid.column s.add(new BoundColumn("fi rstname"))
DataGrid.column s.add(new BoundColumn("la stname"))
DataGrid.DataBi nd();
many thanks
Andy