How to change default row and column count of a C1FlexSheet

Posted by: anildabral3k on 4 September 2019, 4:07 pm EST

  • Posted 4 September 2019, 4:07 pm EST

    I am using C1FlexSheet ver 4.0.20153.497.
    I created an instance of C1FlexSheet, which gave me 50 rows and 10 columns(A to J). I want to achieve following :
    1. Change this default of 50x10 to some custom size of my own.

    2. If I copy data from an Excel sheet, size say 70x20 and paste it in the C1FlexSheet, I only get data in 50x10 and remaining Excel data is lost. Can we set some property(or do something) so that data is not lost and rather C1FlexSheet resizes to the size of data being pasted?

    3. While manually entering the data, in the C1FlexSheet if we reach the default boundary (50x10) then how can I add more blank rows and columns on the fly, like, maybe pressing a TAB key or some other way?

  • Marked as Answer

    Replied 4 September 2019, 8:53 pm EST


    1. In order to specify the number of rows/columns by your own, you can create and add a Sheet to the FlexSheet as follows:

    private void FlexSheet_Loaded(object sender, RoutedEventArgs e)
    flexSheet.AddSheet("Sheet 1", 70, 20);

    2. FlexSheet does not provide any such built-in functionality. However, you can handle the PreviewKeyDown event on FlexSheet and add the required number of rows and columns as follows:

    private void PerformPaste()
    var currentRow = flexSheet.Selection.TopRow;
    var currentCol = flexSheet.Selection.LeftColumn;

    var rowCount = Clipboard.GetText().Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries).Count();
    var neededRows = rowCount - (flexSheet.Rows.Count - currentRow);
    var neededColumns = Clipboard.GetText().Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries).Count() / rowCount - (flexSheet.Columns.Count - currentCol - 1);

    if (neededRows > 0)
    for (int i = 1; i <= neededRows; i++)
    flexSheet.Rows.Add(new Row());

    if (neededColumns > 0)
    for (int i = 1; i <= neededColumns; i++)
    flexSheet.Columns.Add(new Column());

    3. FlexSheet, by default, displays a ContextMenu by right-clicking a cell, which can be used to Insert/Delete Rows/Columns. However, if you want the new rows/columns to be added based on keyboard keys then you have to do this programmatically by handling the PreviewKeyDown event accordingly.

    Please refer to the attached sample( for the above specifications.

  • Replied 5 September 2019, 3:43 pm EST

    Thank you so much Basant. You resolved my issues.

Need extra support?

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

Learn More

Forum Channels