Skip to main content Skip to footer

Creating Viewports in Spread for Silverlight

Spread for SilverLight allows end users to create and use Viewports. People who are already familiar to different versions with Spread must be aware of what a Viewport is. For those who are not aware of this term; “In context with SpreadSheet, a Viewport is a rectangular independent scrollable area which has some specific row and column count ". Now, lets see how you can create it within Spread.

Creating ViewPort

Spread for SilverLight, allows end users to create ViewPorts as per their need. If you have a large Spread Sheet and you want to have different scrollable views, you can split SpreadSheet's current viewport into multiple ViewPorts by simply clicking and dragging the SplitBox (horizontall or vertical). Split box is like scroll thumb located near scroll bar.

Creating ViewPort Using Code

Spread also provides the developers to define Viewports through code.

  1. To create a Column ViewPort you can use the following method:
    public void AddColumnViewport( int columnViewportIndex, double viewportWidth)
    
    where columnViewportIndex is the index and viewportWidth is the width of the column viewport in pixels.
  2. To create a Row ViewPort, you can use the following method :
    public void AddRowViewport( int rowViewportIndex, double viewportHeight)
    
    where rowViewportIndex is the index and viewportHeight is the height of row viewport.

Limit ViewPort Count

You can also limit the maximum number of viewports that an end user can create . In the given code snippet, you need to calculate Column or Row ViewPort count and remove a ViewPort if it is more than the maximum limit.


private void gcSpreadSheet1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)  
{  
      HitTestInformation info = gcSpreadSheet1.HitTest(e.GetPosition(gcSpreadSheet1).X,  
      e.GetPosition(gcSpreadSheet1).Y);  
      if (info.HitTestType == HitTestType.ColumnSplitBox)  
      {  
         vifbool = true;  
      }  
}  

private void gcSpreadSheet1_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)  
{  
      if (vifbool == true)  
      {  
          ViewportInfo vif = gcSpreadSheet1.ActiveSheet.GetViewportInfo();  
          if (vif.ColumnViewportCount > 3)  
          {  
              for (int i =2; i <= vif.ColumnViewportCount; i++)  
              {  
                   // remove the viewport here it exceeds  
                   gcSpreadSheet1.RemoveColumnViewport(i);  
               }  
           }  
      }  
}  

Download the given samples for complete implementation. Download C# Sample Download VB.Net Sample

MESCIUS inc.

comments powered by Disqus