FlexGrid, biding source, IEnumerable question

Posted by: a.sharov on 18 May 2022, 3:43 pm EST

    • Post Options:
    • Link

    Posted 18 May 2022, 3:43 pm EST

    Hi.

    Suppose I have grid which is bound to some BS, based on this BS I customized visualization of grid (say 3 columns instead of 7), all my grid settigns stored in resx file. Then in runtime I bind IEnumerable to datasource property of my bindingsource (which is binded as ds for grid). Data displayed, everything is fine but my grid settings ignored (all,7, columns shown instead of 3, all editable instead of false). I mean, all my visualization settings for grid completely ignored…

    Here is code:

      
    this.BindingSource.AllowNew = false;
     this.BindingSource.DataSource = typeof(MyObj);
    ....
      this.c1FlexGrid1.AutoResize = true;
                this.c1FlexGrid1.ColumnInfo = resources.GetString("c1FlexGrid1.ColumnInfo");
                this.c1FlexGrid1.DataSource = this.BindingSource;
                this.c1FlexGrid1.Dock = System.Windows.Forms.DockStyle.Fill;
                this.c1FlexGrid1.Location = new System.Drawing.Point(0, 0);
                this.c1FlexGrid1.Name = "c1FlexGrid1";
                this.c1FlexGrid1.Rows.Count = 1;
                this.c1FlexGrid1.Size = new System.Drawing.Size(656, 542);
                this.c1FlexGrid1.StyleInfo = resources.GetString("c1FlexGrid1.StyleInfo");
                this.c1FlexGrid1.TabIndex = 0;
                this.c1FlexGrid1.VisualStyle = C1.Win.C1FlexGrid.VisualStyle.Office2010Blue;
    
    

    and how I bind data:

    
    BindingSource.DataSource = rep.GetData(someId);//IEnumerable                    BindingSource.ResetBindings(false);
     c1FlexGrid1.Refresh();
    
    

    Data is shown but all settings from (resources.GetString(“c1FlexGrid1.ColumnInfo”):wink: ignored.

    I’ve tried to use List instead IEnumerable, C1DataCollectionBindingList but same result.

    What I’m doing wrong?

    Thanks in advance.

  • Posted 19 May 2022, 12:48 am EST

    Hi,

    When the DataSource property of the C1FlexGrid is assigned a new Data source, the grid resets the Column collection to reflect the schema of that Data Source. If you are using the Designer to create your custom layout and want to preserve that layout when the DataSource is set, you will need to set the AutoGenerateColumns property of the C1FlexGrid to false before assigning the DataSource.

    You can also use the SetDataBinding method of the C1FlexGrid to set the DataSource of the Grid, which has a preserveLayout parameter to preserve the layout created by the designer.

    Kindly refer to the attached sample showing both approaches.

    FgBinding.zip

    Best Regards,

    Kartik

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels