Changing spreadTable.DataSource or calling DataTable.AcceptChanges() causes columns to resize

Posted by: jackburton-fp on 8 September 2017, 3:07 pm EST

  • Posted 8 September 2017, 3:07 pm EST

    I am having an issue with columns on a WinForms Spread Control. If i change the datasource of the spreadTable or call AcceptChanges on the datatable that is its DataSource all the columns resize. Is there a setting to turn off this behavior? I have AutoGenerateColumns turned off and manually added the columns. Another strange thing is that the spread controls ColumnWidthChanged event does not get raised when they resize. If i manually resize them it does get raised, but not when acceptchanges is called.

  • Replied 8 September 2017, 3:07 pm EST


    The AutoGenerateColumns property indicates whether or not the spreadsheet automatically determines which columns are bound to which data fields. The DataAutoSizeColumns property indicates whether or not the spreadsheet automatically resizes the column as it being bound. In your scenario, you want to also set DataAutoSizeColumns = false.

    fpSpread1.Sheets[0].DataAutoSizeColumns = false;

    The ColumnWidthChanged event fires when column width is changed by end user in the UI (e.g. drag column border in column header, double click column border in column header). The event does not fire when the column width is changed via the application calling API or is changed via data binding.

  • Replied 8 September 2017, 3:07 pm EST

    Perfect, that is exactly what i was looking for. It works as expected now. 

  • Replied 8 September 2017, 3:07 pm EST

    Hello Again,


    I am having another problem related to this, my columns no longer resize but i noticed that the "Multiline" property on the column type gets reset when AcceptChanges is called. Do you have any recommendations on how to prevent this?


  • Replied 8 September 2017, 3:07 pm EST


    I apologize for the delayed response.

    When you call AcceptChanges on the data set, the model for the
    spreadsheet is re-initialized so that any added data will stay in synch. It overrides any of the celltype settings done after assigning the datasource to Spread. To prevent the overriding of these settings, I would suggest you to set the DataAutoCellTypes property to false before calling the AcceptChanges method. This property makes sure that Spread does not automaticaly assigns the celltype to the bound columns. Here is the code snippet for the same:

      private void button1_Click(object sender, EventArgs e)
                fpSpread1.ActiveSheet.DataAutoCellTypes = false;
                DataSet ds1 = (DataSet)fpSpread1.DataSource;
                FarPoint.Win.Spread.CellType.TextCellType tct1 = (FarPoint.Win.Spread.CellType.TextCellType)fpSpread1.ActiveSheet.Columns[1].CellType;

    So, when you initially bound Spread with datasource, it has all its columns celltype set with all the overriden settings such as Multiline property that you have done to the celltypes. Later, when you set the DataAutoCellTypes property to false and then call the AcceptChanges method, then it does not resets the celltype, so none of your celltype settings are overriden.

    Hope it helps.


    Manpreet Kaur

Need extra support?

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

Learn More

Forum Channels