I have a grid which has a number of child grids. I need to hide/change other field properties using code. I am a little lost when/how to do this. I bind the datasource in code. After setting datasource I only see one fieldLayout. Any help will be greatly appreciated.
Thanks
Hello,
Before getting to your question, I have couple of questions to clarify your setup. What do you mean by "grid has number of child grids"? Do you mean that the XamDataGrid has hierarchical data and you have nested content? If this is so, how do you see only one FieldLayout? Is your data structure hierarchical?
Assuming that you have a hierarchical XamDataGrid and you want to toggle the visibility of some fields. Each FieldLayout exposes a Fields collection that contains all of the fields in this layout. You can use this collection to change the Visibility property of the specific field you want. Different field layouts you can find in the FieldLayouts collection of the XamDataGrid. For example, if you want to hide the first field in the nested layout (in the first child layout) you can use the following:
xamDataGrid1.FieldLayouts[0].Fields[0].Visibility = VIsibility.Collapsed;
Please note that, the FieldLayouts are generated only when they are visibile. If you have not expanded the child layout, it will not be generated until you expand at least one record.
Let me know if you have questions on this.
Well that answers why the field layout is not generated when I set datasource. Is there a way to expand/collapse child records? (To generate layouts.)
I got another problem. I set the visiblity of fields like this:
foreach (Field f in xamDGFinish.FieldLayouts[0].Fields) { switch (f.Name) { case "NewLaborCategory": f.Visibility = Visibility.Visible; f.Label = "Labor Category"; f.Row = 0; f.Column = 0; break; case "MatchedContractorCategory": f.Visibility = Visibility.Visible; f.Label = "DCS Labor Category"; f.Row = 0; f.Column = 1; break; case "Files": f.Visibility = Visibility.Visible; break; case "ChosenPastPerformances": f.Visibility = Visibility.Visible; f.Label = "Past Performances"; break; default: f.Visibility = Visibility.Collapsed; break; } }
When I run the program and expand the row it expands but no child records show. I collapse and expand again and child records show up. If I comment out the for loop it shows child records the first time. Any suggestions?
And is there a way to set a grouping in a child grid?
By default XamDataGrid uses virtualization techniques and that is why FieldLayouts are generated/destroyed when they are expanded/collapsed. To turn off this virtualization, you can change the RecordContainerGenerationMode, which is not recommended if you have a lot of data in the XamDataGrid.
Regarding this code snippet, which event are you using to execute this code in ?
Currently, grouping can be performed only on the parent layout and not any child one. In version 9.2, which by the way is just around the corner, you will be able to GroupBy any fieldlayout you like.
That's good news.
Please don't forget to give us your feedback on any new features/controls that you would like to see in our future releases on the link below:
http://devcenter.infragistics.com/Protected/RequestFeature.aspx
Thanks!
I updated to 9.2 and referenced those dlls. And the issue where I have to expand row twice to show child grids is gone. They show up after first time.
PS:
The features you added to the grid in 9.2 are excellent. A lot of the features were ones I wished that were in 9.1. Good Job.
the code is not in a grid event. The code is on a finish event of a wizard control. When finish button is pressed the code that pretains to setting up grid is:
private void setupFinishGrid() { xamDGFinish.FieldLayoutSettings.AutoArrangeCells = Infragistics.Windows.DataPresenter.AutoArrangeCells.Never; xamDGFinish.AutoFit = true; xamDGFinish.DataSource = _lcwCol; foreach (Field f in xamDGFinish.FieldLayouts[0].Fields) { switch (f.Name) { case "NewLaborCategory": f.Visibility = Visibility.Visible; f.Label = "Labor Category"; f.Row = 0; f.Column = 0; break; case "MatchedContractorCategory": f.Visibility = Visibility.Visible; f.Label = "DCS Labor Category"; f.Row = 0; f.Column = 1; break; case "Files": f.Visibility = Visibility.Visible; break; case "ChosenPastPerformances": f.Visibility = Visibility.Visible; f.Label = "Past Performances"; break; default: f.Visibility = Visibility.Collapsed; break; } } }