Hi,
A few years ago, I had some performance problems with WinGrid when refilling the datasource with many items. The solution (in order to maintain the layout) was to clone the DisplayLayout, set a new datasource, and use CopyFrom on the layout to restore the layout. However, I now have a problem when there are ValueLists bound to columns. When using this method, the bound ValueLists in the cloned layout are empty. I've made a small sample project demonstrating the problem. Just create a new Forms application and overwrite with the code below (everything works fine, until you uncomment the specified line). Can anyone help me to solve this? I'm using version 14.2.20142.2132. Thanks in advance.
public partial class Form1 : Form { readonly BindableValueList ValueList = new BindableValueList(); private readonly UltraGrid Grid; public Form1() { InitializeComponent(); ValueList.ValueListItems.Add(1, "First"); ValueList.ValueListItems.Add(2, "Second"); Grid = new UltraGrid { Dock = DockStyle.Fill }; Grid.InitializeLayout += Grid_InitializeLayout; Controls.Add(Grid); Grid.DataSource = CreateDataSource(1); // Uncomment line below to get the problem //ResetDataSource(); } private static UltraDataSource CreateDataSource(int number) { var ds = new UltraDataSource(); ds.Band.Columns.Add("Number", typeof (int)); ds.Rows.Add(new object[] { number }); return ds; } private void ResetDataSource() { var layout = Grid.DisplayLayout.Clone(); Debug.WriteLine(Grid.DisplayLayout.Bands[0].Columns["Number"].ValueList.ItemCount); Debug.WriteLine(layout.Bands[0].Columns["Number"].ValueList.ItemCount); Grid.DataSource = CreateDataSource(2); Grid.DisplayLayout.CopyFrom(layout); } private void Grid_InitializeLayout(object sender, InitializeLayoutEventArgs e) { var column = Grid.DisplayLayout.Bands[0].Columns["Number"]; column.ValueList = ValueList; column.Style = ColumnStyle.DropDownList; } }
Hi Reinier,
Thank you for posting in our forums!
When you use the default overload of the method Clone, it includes All property categories such as Bands and ValueLists. As it is written in our documentation, when Bands and ValueLists flags are applied, each column ValueList object should be cloned as well. Therefore, it should also work in your scenario, but as I verified on my side, it doesn’t, and I can clearly confirm that this is an issue in our code. Your case will be linked to our internal tracking system and the next step will be a senior developer to review my investigation, recognize it is actually an issue and implement appropriate fix.
As a workaround, you can add initially, inside InitializeLayout, the ValueList in UltraGrid’s DisplayLayout ValueLists collection. Once the layout is cloned, it would be available inside the ValueList collection and can be reassigned on the column’s ValueList.
For further reference, please take a look at the attached sample and let me know if the workaround works for you.
Thank you for your assistance. Your workaround works, but now I can't update my ValueList the way I normally do. For example if you change ResetDataSource to:
private void ResetDataSource() { var layout = Grid.DisplayLayout.Clone(); Debug.WriteLine(Grid.DisplayLayout.Bands[0].Columns["Number"].ValueList.ItemCount); Debug.WriteLine(layout.Bands[0].Columns["Number"].ValueList.ItemCount); Grid.DataSource = null; ValueList.ValueListItems.Clear(); ValueList.ValueListItems.Add(1, "New first"); ValueList.ValueListItems.Add(2, "New second"); Grid.DataSource = CreateDataSource(2); Grid.DisplayLayout.CopyFrom(layout); }
You still see the old values. My goal is not to clone the ValueLists, but that the assigment to Form1.ValueList is restored after resetting the datasource (without manually assigning it again). Do you know how I can achieve that?
In order to update the ValueList, you have to place it at the beginning of ResetDataSource method. I understand that you don’t want to manually assign the ValueList each time the InitializeLayout event is raised, but this is the most appropriate workaround for now, until we investigate this issue further for you. As a matter of fact, what happens inside the Clone and CopyFrom methods is exactly the same as the workaround approach. If this is a blocking issue and you are chasing deadlines, I can escalate it to private build and provide you with fix.
Please let me know if you need any further assistance.
I thought that normal ValueLists would not update the dropdown in the grid after changes to that list, but it does. I will use normal ValueLists from now. Thank you for your support.
After further investigation from our development team, we reached to conclusion that instead of using BindableValueList you have to use just ValueList. Using BindableValueList causes anything you change to rebind itself and at the end it ends up clearing out all of the items. As a result, you can change the initial implementation from using BindableValueList to ValueList or stick with the workaround modification added afterwards.
Thank you for using Infragistics Components!
I can create a workaround for now, no problem. Thanks!