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.
- To create a Column ViewPort you can use the following method:
where columnViewportIndex is the index and viewportWidth is the width of the column viewport in pixels.public void AddColumnViewport( int columnViewportIndex, double viewportWidth)
- To create a Row ViewPort, you can use the following method :
where rowViewportIndex is the index and viewportHeight is the height of row viewport.public void AddRowViewport( int rowViewportIndex, double viewportHeight)
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