回复 2楼zongxudong的帖子
我这有一个在 Silvelight 下使用的例子,你可以参考下:
- public MainPage()
- {
- InitializeComponent();
- ConnectionBase.AddExternalConnectionType(typeof(ArrayConnection));
- object[] data = new object[] { "Lotfi", new DateTime(1984, 01, 24), "Annaba", 24501.47 };
- this.gcSpreadSheet1.ActiveSheet.DataSource = data;
- }
- private void GcSpreadSheet_EditEnd(object sender, GrapeCity.Windows.SpreadSheet.UI.EditCellEventArgs e)
- {
- string text = this.gcSpreadSheet1.Sheets[0].Cells[e.Row, e.Column].Text;
- //校验
- }
- }
- public class ArrayConnection : ConnectionBase
- {
- private string[] fields;
- private Array array;
- public override bool CanOpen()
- {
- Array a = this.DataSource as Array;
- //only support 1 or 2 dimensions array.
- return a != null && (a.Rank == 2 || a.Rank == 1);
- }
- public override void Open()
- {
- base.Open();
- this.array = this.DataSource as Array;
- int columnCount = 1;
- if (this.array.Rank == 2)
- {
- columnCount = array.GetLength(1);
- }
- fields = new string[columnCount];
- string fieldsIdea = "";
- for (int i = 0; i < columnCount; i++)
- {
- fieldsIdea = "C" + (i + 1).ToString();
- }
- }
- public override string[] DataFields
- {
- get
- {
- return this.fields;
- }
- }
- public override int GetRecordCount()
- {
- return this.array.GetLength(0);
- }
- protected override object GetRecord(int recordIndex)
- {
- return recordIndex;
- }
- protected override object GetRecordValue(object record, string field)
- {
- if (this.array.Rank == 1)
- {
- return this.array.GetValue((int)record);
- }
- else
- {
- return this.array.GetValue((int)record, Array.IndexOf(fields, field));
- }
- }
- }
复制代码 |