彩票走势图

在Spread中将单元格作为数据源绑定到外部控件中

原创|其它|编辑:郝浩|2012-11-22 10:45:17.000|阅读 290 次

概述:在Spread你可以将一系列的单元格作为数据源绑定到一个外部的控件,比如说数据表格控件,文中的图片显示出了所涉及的对象。

# 慧都年终大促·界面/图表报表/文档/IDE等千款热门软控件火热促销中 >>

在Spread你可以将一系列的单元格作为数据源绑定到一个外部的控件,比如说数据表格控件,下面的图显示出了所涉及的对象。

在Spread中将单元格作为数据源绑定到外部控件中

在这个过程中所包含了以下的对象:

SpreadDataView

SpreadDataRowView

ISpreadDataViewDataFormatter

ISpreadDataViewMapper

DefaultSpreadDataViewDataFormatter

DefaultSpreadDataViewMapper

我们来看一下实例:

创建一个自定义的类,代码如下:

C#

public class MySpreadDataViewDataFormatter : ISpreadDataViewDataFormatter
{
private SpreadDataColumn column;
private SheetView sheetView;
public SheetView SheetView;
{
get { return sheetView; }
set { sheetView = value; }
}
public MySpreadDataViewDataFormatter(SpreadDataColumn ownerColumn,SheetView sheetView)
{
if (ownerColumn == null)
{
throw new ArgumentNullException("ownerColumn");
}
column = ownerColumn;
this.SheetView = sheetView;
}
public object GetCellValue(Cell cell)
{
object ret = null;
try
{
ret = this.SheetView.GetValue(cell.Row.Index, cell.Column.Index);
ret += ": Customized format";
}
catch
{
ret = " No value";
}
return ret;
}
public void SetCellValue(Cell cell, object value)
{
this.SheetView.SetValue(cell.Row.Index, cell.Column.Index, value + ": Customized format");
}
}
// Assign new formatter
dataSet = BuildDataSet(5,5);
this.spreadDataBindingAdapter1.Spread = this.fpSpread1;
this.spreadDataBindingAdapter1.SheetName = this.fpSpread1.ActiveSheet.SheetName;
this.spreadDataBindingAdapter1.DataSource = dataSet.Tables[0];
spreadDataBindingAdapter1.MapperInfo = new MapperInfo(1, 2, 3, 4);
MySpreadDataViewDataFormatter testFormatter = new MySpreadDataViewDataFormatter
(this.spreadDataBindingAdapter1.SpreadDataView.Columns[2], fpSpread1.ActiveSheet);
this.spreadDataBindingAdapter1.SpreadDataView.Columns[2].Formatter = testFormatter;
this.spreadDataBindingAdapter1.FillSpreadDataByDataSource();

从ISpreadDataViewMapper继承创建一个自定义的映射器,代码如下:

C#

{
...
}
//Assign customized Mapper for SpreadDataView
dataSet = BuildDataSet(5,5);
this.spreadDataBindingAdapter1.Spread = this.fpSpread1;
this.spreadDataBindingAdapter1.SheetName = this.fpSpread1.ActiveSheet.SheetName;
this.spreadDataBindingAdapter1.DataSource = dataSet.Tables[0];
MySpreadDataViewMapper testMapper = new MySpreadDataViewMapper ();
this.spreadDataBindingAdapter1.SpreadDataView.Mapper = testMapper;
spreadDataBindingAdapter1.MapperInfo = new MapperInfo(1, 2, 3, 4);
this.spreadDataBindingAdapter1.FillSpreadDataByDataSource();

VB

Public Class MySpreadDataViewMapper
Implements FarPoint.Win.Spread.Data.ISpreadDataViewMapper
...
End Class
dataSet = BuildDataSet(5, 5)
Me.spreadDataBindingAdapter1.Spread = Me.fpSpread1
Me.spreadDataBindingAdapter1.SheetName = Me.fpSpread1.ActiveSheet.SheetName
Me.spreadDataBindingAdapter1.DataSource = dataSet.Tables(0)
Dim testMapper As New MySpreadDataViewMapper()
Me.spreadDataBindingAdapter1.SpreadDataView.Mapper = testMapper
spreadDataBindingAdapter1.MapperInfo = New MapperInfo(1, 2, 3, 4)
Me.spreadDataBindingAdapter1.FillSpreadDataByDataSource()

标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@pclwef.cn

文章转载自:慧都控件

为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP