找回密码
 立即注册

QQ登录

只需一步,快速开始

zongxudong
初级会员   /  发表于:2013-11-1 14:38  /   查看:9296  /  回复:11
ConnectionBase.AddExternalConnectionType(type)
使用了这个列子的代码后,  还是抛出 NotSupportedException was unhandled by user code 异常.
是不是有什么特别的地方需要注意. 我调试后感觉我注册的类型根本就没有调用 CanOpen 方法.  这个类型应该在什么时候注册?

11 个回复

倒序浏览
zongxudong
初级会员   /  发表于:2013-11-1 15:12:00
沙发
我之前在wpf里面用 ConnectionBase 好像没有问题, 现在是 Silverlight 不知道为什么不行
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2013-11-1 19:00:00
板凳
回复 2楼zongxudong的帖子

我这有一个在 Silvelight 下使用的例子,你可以参考下:

  1. public MainPage()
  2.         {
  3.             InitializeComponent();
  4.             ConnectionBase.AddExternalConnectionType(typeof(ArrayConnection));

  5.             object[] data = new object[] { "Lotfi", new DateTime(1984, 01, 24), "Annaba", 24501.47 };

  6.             this.gcSpreadSheet1.ActiveSheet.DataSource = data;
  7.         }

  8.         private void GcSpreadSheet_EditEnd(object sender, GrapeCity.Windows.SpreadSheet.UI.EditCellEventArgs e)
  9.         {
  10.             string text = this.gcSpreadSheet1.Sheets[0].Cells[e.Row, e.Column].Text;
  11.             //校验
  12.         }
  13.     }

  14.     public class ArrayConnection : ConnectionBase
  15.     {

  16.         private string[] fields;

  17.         private Array array;

  18.         public override bool CanOpen()
  19.         {

  20.             Array a = this.DataSource as Array;

  21.             //only support 1 or 2 dimensions array.

  22.             return a != null && (a.Rank == 2 || a.Rank == 1);

  23.         }

  24.         public override void Open()
  25.         {

  26.             base.Open();

  27.             this.array = this.DataSource as Array;

  28.             int columnCount = 1;

  29.             if (this.array.Rank == 2)
  30.             {

  31.                 columnCount = array.GetLength(1);

  32.             }

  33.             fields = new string[columnCount];
  34.             string fieldsIdea = "";
  35.             for (int i = 0; i < columnCount; i++)
  36.             {

  37.                 fieldsIdea = "C" + (i + 1).ToString();

  38.             }

  39.         }

  40.         public override string[] DataFields
  41.         {

  42.             get
  43.             {

  44.                 return this.fields;

  45.             }

  46.         }

  47.         public override int GetRecordCount()
  48.         {

  49.             return this.array.GetLength(0);

  50.         }

  51.         protected override object GetRecord(int recordIndex)
  52.         {

  53.             return recordIndex;

  54.         }

  55.         protected override object GetRecordValue(object record, string field)
  56.         {

  57.             if (this.array.Rank == 1)
  58.             {

  59.                 return this.array.GetValue((int)record);

  60.             }

  61.             else
  62.             {

  63.                 return this.array.GetValue((int)record, Array.IndexOf(fields, field));

  64.             }

  65.         }

  66.     }
复制代码
回复 使用道具 举报
zongxudong
初级会员   /  发表于:2013-11-4 16:43:00
地板
我之前就一直在使用这个方法. 但是我始终没能在 Silverlight 版本上成功过.
不管我在哪里注册自定义的 Connection , 都不能进入自定义里面去,  感觉像是没注册过,  WPF反而就可以.
我几乎检查了全部的细节, 就是不知道哪里有遗漏.
不知道, 你们是不是能够正常调用. 如果可以, 能不能发个测试项目来我试试看
回复 使用道具 举报
zongxudong
初级会员   /  发表于:2013-11-4 16:51:00
5#
嗨, 不知道. 这个是不是产品的Bug 哦. 就算我是建立一个空项目, 完全Copy 你的代码. 都不能测试成功.
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2013-11-5 12:16:00
6#
回复 5楼zongxudong的帖子

这是我的测试Demo,在我这边测试成功:

10860.zip (1.6 MB, 下载次数: 883)
回复 使用道具 举报
zongxudong
初级会员   /  发表于:2013-11-5 12:43:00
7#
你好, 你们的代码我测试过了. 还是不行. 不能支持自定义的 ArrayConnection
不过, 我换成引用最新的版本.  V2.0.50727 这个就可以测试成功

V 1.0.7.0 我现在用的这个版本号就不可以.  
呵呵.
回复 使用道具 举报
zongxudong
初级会员   /  发表于:2013-11-5 12:51:00
8#
不对呀. 我看你们的原始项目, 也是用的 V1.0.7.0 呀, 你们怎么会测试成功的也
回复 使用道具 举报
zongxudong
初级会员   /  发表于:2013-11-5 12:57:00
9#
我使用 V1.0.7.0 的版本运行的效果  
QQ截图20131105125334.png
改用 V2 的版本就是可以

QQ截图20131105125506.png
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2013-11-5 14:34:00
10#
回复 9楼zongxudong的帖子

zongxudong 你好,
我的测试版本是:

Untitled.png

不知道你的V2.0.50727 版本是从哪里下载的安装包?

另外,如果是试用,建议使用最新版:
Spread WPF-Silverlight 7.0 已经发布,新增类似微软Excel 2013的UI触摸行为和样式支持,在导入、导出Excel文件和公式计算性能上提高了50-200%。新增40+种图表类型、公式编辑器、图片支持等更多功能。
http://www.gcpowertools.com.cn/products/spread_wpf.htm
回复 使用道具 举报
12下一页
您需要登录后才可以回帖 登录 | 立即注册
返回顶部