...using Infragistics2.Win.UltraWinGrid.v9.2.dll
On FormA I have a grid named MissingGrid. I need to open FormB with two grids (Grid1 & Grid2) and I want these two grids to be an exact copy of MissingGrid (minus the actual data). All three grids will be bound to the same schema (new BindingList<MissingLanguageDTO>). None of the grids have any design time schema or column collections. In FormA I use the InitializeLayout() method to define MissingGrid. My goal was to avoid duplicating this code in two forms.
QUESTION:
How do I copy the layout, including columns, size, position, header properties, etc at runtime from one grid to another?
WHAT I'M DOING NOW:
in the constructor of FormB I'm passing the stream from the following code in FormA. this iprivate void button1_Click(object sender, EventArgs e) { MemoryStream ms = new MemoryStream(); MissingGrid.DisplayLayout.Save(ms, UltraGrid.PropertyCategories.All); LanguageTabMissingPopup popupForm = new LanguageTabMissingPopup(fileKey, ms); popupForm.ShowDialog(); }
In FormB I have:
protected override void OnLoad(EventArgs e) { base.OnLoad(e); //essentially copy the grid layout from the parent form this.TheGridLayout.Position = 0; RequestGrid.DisplayLayout.Load(TheGridLayout, UltraGrid.PropertyCategories.All); this.TheGridLayout.Position = 0; ImagedGrid.DisplayLayout.Load(TheGridLayout, UltraGrid.PropertyCategories.All); BindGrid(); ToggleButtons(); } private void BindGrid() { ImagedGrid.SetDataBinding(new BindingList<MissingLanguageDTO>( MissingDocs.Where(m => m.IsToBeImagedToFile).ToList()), null, true); RequestGrid.SetDataBinding(new BindingList<MissingLanguageDTO>( MissingDocs.Where(m => !m.IsToBeImagedToFile).ToList()), null, true); }
When FormB opens, Grid1 & Grid2 only have 3 of the fields that are visible on MissingGrid. My understanding is that the DisplayLayou.Load() method should bring over the grid, its columns with their configurations.
Strangly when I break in the InitializeRow() method in FormB all of the properties are indeed set as I expect them, the grid simply is not reflecting that. Below you see that only LineNumbers is hidden. This is as expected.
e.Row.Band.Columns.Band.Columns.All {Infragistics.Shared.IKeyedSubObject[13]}+ [0] {GroupNumber} + [1] {LanguageIndicator} + [2] {State} + [3] {DateOfService} + [4] {GroupStartDate} + [5] {GroupEndDate} + [6] {LangIndStartDate} + [7] {LangIndStopDate} + [8] {LineNumbers [hidden]} + [9] {IsToBeImagedToFile} + [10] {GroupDateRange} + [11] {LanguageDateRange} + [12] {ClaimNo}
I think you need to load the layout AFTER you bind the grid instead of before. The layout will not work unless the current data structure of the grid matches the layout and if you load the layout first, the grid has no data structure at that point.
How would I check whether the the current data source of the grid matches the layout or not with .displaylayout.load("fileName.layout", PropertyCategories.All) by C#.
Hi Lala,
There's no way to validate the layout, other than to simply load it into the grid and see if it works.
I suppose if you wanted to, you could load the layout into an UltraGridLayout variable and then loop through all of the bands and columns and then compare those to the bands and columns in your grid to make sure they all match up.