Spread中默认会显示没有数据的行和列,不过有时候我们只希望显示有数据的最大区域,这时候我们通过以下代码来实现:

 
fpSpread1.ActiveSheet.RowCount = fpSpread1.ActiveSheet.NonEmptyRowCount;

    fpSpread1.ActiveSheet.ColumnCount = fpSpread1.ActiveSheet.NonEmptyColumnCount;

复制代码

然而,有时候我们不仅需要只显示有数据的区域,我们还希望【当滚动条滚动到最大显示范围时,能够动态增加行/列数】,比如:当前SheetView的 RowCount = 50;ColumnCount=20;,当滚动横向滚动条至最右边时,已经显示第20列,此时我再滚动横向滚动条,我希望能够增加一列。

这时候我们可以通过Spread滚动条的事件来实现这一需求:

  1.        
    private void Form1_Load(object sender, EventArgs e)
    
            {
    
    
    
                fpSpread1.ActiveSheet.RowCount = 50;
    
                fpSpread1.ActiveSheet.ColumnCount = 20;
    
    
    
                //fpSpread1.ActiveSheet.RowCount = fpSpread1.ActiveSheet.NonEmptyRowCount;
    
                //fpSpread1.ActiveSheet.ColumnCount = fpSpread1.ActiveSheet.NonEmptyColumnCount;
    
    
    
    
    
                fpSpread1.HorizontalScrollBar.ButtonClick += new FarPoint.Win.Spread.FpScrollBarButtonClickEventHandler(HorizontalScrollBar_ButtonClick);
    
                fpSpread1.VerticalScrollBar.ButtonClick += new FarPoint.Win.Spread.FpScrollBarButtonClickEventHandler(VerticalScrollBar_ButtonClick);
    
            }
    
    
    
            void VerticalScrollBar_ButtonClick(object sender, FarPoint.Win.Spread.FpScrollBarButtonClickEventArgs e)
    
            {
    
                if (fpSpread1.GetViewportBottomRow(0) == fpSpread1.ActiveSheet.RowCount)
    
                {
    
                    if (e.Button.ChangeType == FarPoint.Win.Spread.ChangeType.SmallChange)
    
                    {
    
                        fpSpread1.ActiveSheet.RowCount += 1;
    
                    }
    
                }
    
            }
    
    
    
            void HorizontalScrollBar_ButtonClick(object sender, FarPoint.Win.Spread.FpScrollBarButtonClickEventArgs e)
    
            {
    
                if (fpSpread1.GetViewportRightColumn(0) == fpSpread1.ActiveSheet.ColumnCount)
    
                {
    
                    if (e.Button.ChangeType == FarPoint.Win.Spread.ChangeType.SmallChange)
    
                    {
    
                        fpSpread1.ActiveSheet.ColumnCount += 1;
    
                    }
    
                }            
    
            }
    
    复制代码
    Vs2010 + Spread .NET 6.0.3505 + C#
6015_Scroll_C#.zip (10.19 K, 下载次数:9)