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 Reply Children
No Data