I've got a UltraWinGrid bound to a UltraDataSource. I've used design-time to create the column/band layouts in the UltraDataSource. The UltraWinGrid is design-time bound to the UltraDataSource.
In code in my LoadData() routine, I load the UltraDataSource row by row, band by band (one root band, one child band("Location")) like this:
For Each t As RFATariff In Card.TariffList.Values Dim dr As UltraDataRow = dsPricing.Rows.Add
dr("TariffKey") = t.TariffKey
... etc ...
Dim LocationRows As UltraDataRowsCollection = dr.GetChildRows("Location") For Each l As RFALocation In t.LocationList.Values Dim ldr As UltraDataRow = LocationRows.Add ldr("LocationKey") = l.LocationKey ...etc...
Next Next For Each c As UltraGridColumn In dgrPricing.DisplayLayout.Bands(0).Columns c.PerformAutoResize(PerformAutoSizeType.AllRowsInBand, True) Next For Each c As UltraGridColumn In dgrPricing.DisplayLayout.Bands("Location").Columns c.PerformAutoResize(PerformAutoSizeType.AllRowsInBand, True) Next
All this works fantastic.
My problem comes when I want to reload the form.
I tried dsPricing.Rows.Clear() but this cleans out the layout of the ultradatasource....
I hate it if I'm missing something simple, but how can I just clear out the datarows from the entire data source without resetting properties/settings at the same time?
Hi,
What exactly do you mean by this?
grantboggs said:I tried dsPricing.Rows.Clear() but this cleans out the layout of the ultradatasource....
Clearing the rows collection should not have any effect on the data structure. The Bands and columns should not be affected by this.
Hi Mike,
What I meant was:
When you do the dsPricing.Rows.Clear(), the associated UltraGrid loses all it's layout information.
It's so strange to me that you can create an UltraGrid layout in the design-time designer, attach the UltraDatasource and everything works fine-- but clear out the rows in the UltraDatassource and all your grid layout settings go with it.
I expected the grid component to maintain it's layout settings even if the bound datasource was removed or empty. ;-)
I've since solved the issue by moving the grid layout code into the Initialize_Layout event. Everything working fine now.
To what issue are you referring? Are you saying that even when you save the layout and re-load it, it's not working? The grid is still losing it's layout?
I have no explanation for that. I don't see anything obviously wrong with the code you have here, but it's always hard to tell from a code snippet when you can't actually run it.
Perhaps you could try to duplicate the problem in a small sample project and post it here so I can take a look.
As mentioned, I used the DisplayLayout.SaveXML method to save the layout the stream and tried to load using the LoadLayout metho. Please guide where i m going wrong
In fthe Form_Load, adding the code for saving the Layout in xml format.
In Form_Load System.IO.FileStream fs = null; string XML_LAYOUT_FILE_PATH = @"C:\\testlayout.xml"; // Open a new file to save the layout to. fs = new System.IO.FileStream(XML_LAYOUT_FILE_PATH, System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.None); this.benefitPlanIncomeUltraGrid.DisplayLayout.SaveAsXml(fs, PropertyCategories.All); fs.Close();
In the button click event, clearing the gridrows.
private void clearAllButton_Click(object sender, EventArgs e) { System.IO.FileStream fs = null; string XML_LAYOUT_FILE_PATH = @"C:\\testlayout.xml"; MessageBox.Show(benefitPlanIncomeUltraGrid.Rows.Count.ToString()); foreach (UltraGridRow rows in benefitPlanIncomeUltraGrid.Rows) { if (!rows.IsDeleted) { rows.Delete(false); } rows.Refresh(); } benefitPlanIncomeUltraGrid.Rows.Refresh(RefreshRow.ReloadData, true); //MessageBox.Show(benefitPlanIncomeUltraGrid.Rows.Count.ToString()); //benefitPlanIncomeUltraGrid.Rows.Refresh(RefreshRow.ReloadData, true); // this.benefitPlanIncomeUltraGrid.ResetDisplayLayout(); this.benefitPlanIncomeUltraGrid.DisplayLayout.Bands[0].RowLayouts.Clear(); // this.benefitPlanIncomeUltraGrid.DisplayLayout.Rows.Band.ResetRowLayouts(); fs = new System.IO.FileStream(XML_LAYOUT_FILE_PATH, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read); this.benefitPlanIncomeUltraGrid.DisplayLayout.LoadFromXml(fs, PropertyCategories.All); fs.Close(); }
Please help to resove the issue. It is very urgent.
Thanks,
JIJIL
Mike Saltzman"] Your workaround seems reasonable, but the user will lose any state-specific information. For example, if the user resized a column, it will revert to it's original size when you clear the rows. So what you might want to do is use the grid.DisplayLayout.Save method to save the layout to a stream and then re-load it after you clear the rows.
Your workaround seems reasonable, but the user will lose any state-specific information. For example, if the user resized a column, it will revert to it's original size when you clear the rows. So what you might want to do is use the grid.DisplayLayout.Save method to save the layout to a stream and then re-load it after you clear the rows.
Nice... sounds just like what I needed to do. I'll give that a go and see how it works out. Thanks for the tip!
Great product and excellent support. Keep up the good work!
I agree that it's strange. That should not be happening. There's no reason why the grid should be losing it's layout when you simply clear the rows collection - unless clearing the root-level rows collection is somehow destroying the child band and causing the UltraDataSource to send a Reset notification.
Sounds like a bug to me.