...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}
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.
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 Sunil,
How did you create the layout you are loading?
What do you mean when you say it's not working? What, exactly, is not working?
Does the layout you saved contain 100 columns where 80 of them are hidden?
in order for a layout to properly load into the grid, it has to match the data source into which the grid is bound. So that means all of the columns have to exist in the layout and they must all have the same keys as the columns in the data source. The same goes for the band's and their keys, including the root band and any child bands.
Hi,
Here I have bind a datatable to the ultragrid with 100 columns. But I have a layout saved with 20 columns. So I expect as soon as I load a layout with ".displaylayout.load("fileName.layout", PropertyCategories.All)" it should hide remaining 80 columns and make visible 20 columns.This behaviour is not working correctly. Some time it works but sometime not.
Can you please help me out in this?
Thanks,Sunil
Here I have assigned a datatable to the ultragrid with 100 columns. But I have a layout saved with 20 columns. So I expect as soon as I load a layout with ".displaylayout.load("fileName.layout", PropertyCategories.All)" it should hide remaning 80 columns and make visible 20 columns.This behaviour is not working correctly. Some time it works but sometime not.