Column spanning for dynamically added columns-C#

Posted by: droopy5 on 8 September 2017, 1:25 pm EST

  • Posted 8 September 2017, 1:25 pm EST

    Hi


      I have the 4th,5th and 6th columns for a particular row in a spread to be spanned.I dynamically add new columns.I want these newly added columns also to be spanned with the previous ones for the same row.How do i code for that?..Am using C# code..Please help me..Its urgent.


     


    Thanks


     

  • Replied 8 September 2017, 1:25 pm EST

    If you can successfully execute a span initially what is the issue with doing it after a column addition?  If the issue is knowing whether the previous cell is a part of a span you could call GetCellSpan on the previous column to determine if it is a part of a span and just adjust the span as needed.

     

    dim cr as FarPoint.Win.Spread.Model.CellRange

    cr = FpSpread1.ActiveSheet.GetCellSpan(currRow, currCol-1)

    if (Not (cr is Nothing)) then

                FpSpread1.ActiveSheet.AddSpanCell(cr.Row, cr.Column, cr.RowCount, cr.ColumnCount + 1)
    End If

  • Replied 8 September 2017, 1:25 pm EST

    Hello,


    This code sets a tag property on the original beginning and ending columns. It then reacts to the ColumnChanged event and rechecks the spans. If the column was inserted within the original span, the span is removed and readded. Good Luck!


    using System.Text.RegularExpressions;


    private int _ColumnCount;
    private int _SpanColumnCount;


        // Set up tags on columns when setting up original span. Also set _SpanColumnCount here.
        column.Tag = String.Format("AnchorColumn={0};", column.Index);
        column.Tag = String.Format("AnchorColumn={0};", column.Index);


    private void FpSpread1_Sheet1_ColumnChanged(object sender, FarPoint.Win.Spread.SheetViewEventArgs e)
    {
        // New column added so check spans.
        if (this.FpSpread1.ActiveSheet.ColumnCount > _ColumnCount) {
            _ColumnCount = this.FpSpread1.ActiveSheet.ColumnCount;
            int anchorColumn;
            int endingColumn;
            foreach (FarPoint.Win.Spread.Column column in this.FpSpread1.ActiveSheet.Columns) {
                string tag = Convert.ToString(column.Tag);
                if (tag.Trim.Length > 0) {
                    if (Regex.IsMatch(tag, @"AnchorColumn=(\\d+);", RegexOptions.IgnoreCase)) {
                        anchorColumn = Convert.ToInt32(Regex.Match(tag, @"AnchorColumn=(\\d+);", RegexOptions.IgnoreCase).Groups(1).Value);
                    }
                    else if (Regex.IsMatch(tag, @"EndingColumn=(\\d+);", RegexOptions.IgnoreCase)) {
                        endingColumn = Convert.ToInt32(Regex.Match(tag, @"EndingColumn=(\\d+);", RegexOptions.IgnoreCase).Groups(1).Value);
                        break; 
                    }
                }
            }
            if (endingColumn - anchorColumn > _SpanColumnCount) {
                this.FpSpread1.ActiveSheet.RemoveSpanCell(yourRow, anchorColumn);
                // Reset your span cell here using the new column length.
            }
        }
    }

Need extra support?

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

Learn More

Forum Channels