I love DevExpress controls. They do so much for you.... of course, the flip side is that there are so many properties and methods that even the simplest tasks can be a bit daunting.
One of the most common tasks when dealing with grids would be to set up a Master-Detail relationship. For my own future reference I've written down the properties and methods involved in setting this up at design-time.
- Add Grid [Grid_Master]
- Set up columns
- Grid_Master.SettingsDetail.ShowDetailRow = true
- Smart Tag -> Edit Template -> Detail Row.
- Add Detail Grid here [Grid_Detail]
- Grid_Detail.SettingsDetail.IsDetailGrid = true
If using custom databinding, hook up Grid_Detail.Databinding event. In Grid_Detail.Databinding, add similar code to the following:
//The detail data is the assets that make up each Purchase Order
ASPxGridView detailGrid = (ASPxGridView)sender;
detailGrid.KeyFieldName = "ID";
int id = (int)detailGrid.GetMasterRowKeyValue();
DataTable table = new DataTable();
table.Columns.Add("ID", typeof(int));
table.Columns.Add("AssetTypeName", typeof(string));
table.Columns.Add("SerialNumber", typeof(string));
table.Columns.Add("SalesPrice", typeof(float));
table.Columns.Add("Location", typeof (string));
table.Columns.Add("Discount", typeof (float));
Invoice invoice = InvoiceModel.GetInvoiceForID(id);
if (invoice != null)
{
foreach (AssetItem asset in invoice.MyInvoiceItems)
{
table.Rows.Add(new object[] { asset.ID,
asset.AssetTypeName, asset.SerialNumber, asset.SalesPrice,
asset.Location, asset.Discount});
}
detailGrid.DataSource = table;
}