Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1075
ValueList lost after cloning DisplayLayout
posted

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;
    }

  }
Parents
  • 4625
    Offline posted

    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.

    GridCloneDisplayLayout.zip
Reply Children