With the Developer Express Grid, the latest LLBLGen (20Dec) and the Firebird database
populating the grid:
BoatCollection bc = new BoatCollection();
bc.GetMulti(null);
grdBoats.DataSource = bc;
retrieving the current row (doesn't work - gives undefined value for dr
if (gvBoats.SelectedRowsCount > 0)
{
DataRow dr = gvBoats.GetDataRow(gvBoats.GetSelectedRows()[0]);
int id = int.Parse(dr["BtId"].ToString());
if(new DlgBoatEdit(id).ShowDialog() == DialogResult.OK)
{
LoadBoats();
}
}
however if I use GetMultiAsDataTable to populate the grid, the items don't display in the grid, but the selection of the current row (above code) does.
BoatCollection bc = new BoatCollection();
grdBoats.DataSource = BoatCollection.GetMultiAsDataTable(null,0,null);
I have endeavoured to get around the problem by creating a (generic) CollectionToDataTable method
private DataTable CollectionToDataTable(EntityCollectionBase collection, EntityBase entity)
{
DataTable dt = new DataTable();
for (int i=0; i<entity.Fields.Count;i++)
{
dt.Columns.Add(entity.Fields[i].Name, entity.Fields[i].DataType);
}
foreach(EntityBase eb in collection)
{
DataRow row = dt.NewRow();
for (int i=0; i<entity.Fields.Count;i++)
{
row[eb.Fields[i].Name] = eb.Fields[i].CurrentValue;
}
dt.Rows.Add(row);
}
return dt;
}
And this now seems to work
BoatCollection bc = new BoatCollection();
BoatEntity boat = new BoatEntity();
bc.GetMulti(null);
grdBoats.DataSource = CollectionToDataTable(bc,boat);
My first question - is my CollectionToDataTable method safe to use?
Secondly - do you have any idea why this is causing a problem?