Hi guys,
My data source is an ObservableCollection<IInterface> and this IInterface has a property called Items of type ObservableCollection<IInterface>. The problem that i have is showing the children without the header and share the same column layout for the parent. I have code to handle AssigningFieldLayoutToItem and i am creating a second fields layout there based on the parent layout. The problem is i need to reflect the changes to the parent/default layout into the child/second layout, and by changes i mean column position, column resizing.
I am attaching an image of what i would like to achieve. Any suggestions?
Thanks,
Stefan
Sorry Stenfanie, can't help you out with that one. I was just trying to get rid of the labels. It wouldn't really be a tree if the rows were all at the same level. You only have two levels right?
Hi rodyager,
I applied the code you supplied above, but I figured out that just the labels are hidden for the children. Is it also possible to align the colums of parent and all children? Exactly like the first question of the thread?
Stefanie
brilliant, thanks for sharing.
Here is how I accomplished it for what it is worth...
Notice in "GetStructureFieldLayout" where I hide the label given a specifc layout.
Rod
void theDataGrid_AssigningFieldLayoutToItem(object sender, AssigningFieldLayoutToItemEventArgs e) { if (((DataRowView)(e.Item)).Row["parent_id"].ToString().Length == 0) { if (theDataGrid.FieldLayouts.Exists("ParentLayout")) { e.FieldLayout = theDataGrid.FieldLayouts["ParentLayout"]; } else { theDataGrid.FieldLayouts.Add(GetStructureFieldLayout("ParentLayout")); e.FieldLayout = theDataGrid.FieldLayouts["ParentLayout"];
//If this item has a product_id value, then the record should not be editable. //If the item does not have a product_id value, then AllowEdit on the //model_id, part_id, and quantity cells. } } else { if (theDataGrid.FieldLayouts.Exists("ChildLayout")) { e.FieldLayout = theDataGrid.FieldLayouts["ChildLayout"]; } else { theDataGrid.FieldLayouts.Add(GetStructureFieldLayout("ChildLayout")); e.FieldLayout = theDataGrid.FieldLayouts["ChildLayout"];
//If this item has a product_id value, then the record should not be editable. //If the item does not have a product_id value, then AllowEdit on the //model_id, part_id, and quantity cells. } } }
private FieldLayout GetStructureFieldLayout(string keyName) { FieldLayout fl = new FieldLayout();
fl.Key = keyName; if (keyName == "ChildLayout") fl.Settings.LabelLocation = LabelLocation.Hidden;
Field fld = new Field(); fld.Name = "model_id"; fld.Settings.CellValuePresenterStyle = Application.Current.FindResource("leftBorderHyperlinkCell") as Style; fld.Label = "Model ID"; fld.Settings.CellMinWidth = 150.0; fld.Settings.AllowEdit = false; fl.Fields.Add(fld);
fld = new Field(); fld.Name = "part_id"; fld.Settings.CellValuePresenterStyle = Application.Current.FindResource("hyperlinkCell") as Style; fld.Label = "Part ID"; fld.Settings.CellMinWidth = 100.0; fld.Settings.AllowEdit = false; fl.Fields.Add(fld);
fld = new Field(); fld.Name = "serial_id"; fld.Settings.CellValuePresenterStyle = Application.Current.FindResource("cellValuePresenter") as Style; fld.Label = "Serial ID"; fld.Settings.CellMinWidth = 100.0; fld.Settings.AllowEdit = false; fl.Fields.Add(fld);
fld = new Field(); fld.Name = "product_id"; fld.Settings.CellValuePresenterStyle = Application.Current.FindResource("hyperlinkCell") as Style; fld.Label = "Product ID"; fld.Settings.CellMinWidth = 100.0; fld.Settings.AllowEdit = false; fl.Fields.Add(fld);
fld = new Field(); fld.Name = "quantity"; fld.Settings.CellValuePresenterStyle = Application.Current.FindResource("cellValuePresenter") as Style; fld.Label = "Quantity"; fld.Settings.AllowEdit = false; fl.Fields.Add(fld);
//The following four fields are needed to show the hierarchy in the grid. fld = new Field(); fld.Name = "PRODUCT_STRUCTURE_NEST"; fl.Fields.Add(fld);
fld = new Field(); fld.Name = "product_structure_id"; fld.Visibility = Visibility.Hidden; fl.Fields.Add(fld);
fld = new Field(); fld.Name = "parent_id"; fld.Visibility = Visibility.Hidden; fl.Fields.Add(fld);
fld = new Field(); fld.Name = "sequence"; fld.Visibility = Visibility.Hidden; fl.Fields.Add(fld);
return fl; }
Hi Stefan -
As I mentioned in this other post http://forums.infragistics.com/forums/p/5873/26544.aspx#26544 which asks a similar question, there is currently no easy way to do this. If you would like this capability to be added to the XamDataGrid in a future release please submit a feature request here (http://devcenter.infragistics.com/Protected/RequestFeature.aspx) to help move this feature up in the priority list.
Joe