回复 1楼hptj的帖子
tableview 本身不能绑定数据源,它的数据源基于 CellRange,可以通过以下方法实现,先绑定CellRange数据源,在CellRange基础上设置 TableView:
- DataSet ds = new DataSet();
- DataTable dt = default(DataTable);
- dt = new DataTable();
- dt.Columns.Add(new DataColumn("Number1", typeof(string)));
- dt.Columns.Add(new DataColumn("Number2", typeof(string)));
- dt.Columns.Add(new DataColumn("Number3", typeof(string)));
- dt.Columns.Add(new DataColumn("Text1", typeof(string)));
- dt.Columns.Add(new DataColumn("Text2", typeof(string)));
- dt.Columns.Add(new DataColumn("Text3", typeof(string)));
- dt.Columns.Add(new DataColumn("Text4", typeof(decimal)));
- dt.Rows.Add(new object[] { "101", "1", "0", "Num1", "Num2", "Num3", 21000 });
- dt.Rows.Add(new object[] { "201", "2", "0", "a", "b", "c", 9400 });
- dt.Rows.Add(new object[] { "203", "2", "0", "Jan", "Feb", "March", 4550 });
- dt.Rows.Add(new object[] { "301", "3", "1", "First", "Second", "Third", 32000 });
- dt.Rows.Add(new object[] { "302", "3", "1", "Test", "Test1", "Test2", 13280 });
- dt.Rows.Add(new object[] { "204", "2", "0", "Mon", "Tues", "Wed", 1700 });
- dt.Rows.Add(new object[] { "303", "3", "1", "Week1", "Week2", "Week3", 36080 });
- dt.Rows.Add(new object[] { "402", "4", "1", "d", "e", "f", 31500 });
- dt.Rows.Add(new object[] { "405", "4", "1", "July", "August", "September", 4958 });
- dt.Rows.Add(new object[] { "102", "1", "0", "next", "aaa", "max", 1539 });
- ds.Tables.Add(dt);
- FarPoint.Win.Spread.Data.SpreadDataBindingAdapter Sdba = new FarPoint.Win.Spread.Data.SpreadDataBindingAdapter();
- Sdba.DataSource = ds.Tables[0];
- Sdba.Spread = fpSpread1;
- Sdba.SheetName = fpSpread1.ActiveSheet.SheetName;
- Sdba.AutoGenerateRow = true;
- Sdba.DataAutoCellTypes = false;
- Sdba.MapperInfo = new FarPoint.Win.Spread.Data.MapperInfo(2, 0, 10, 7);
- Sdba.FillSpreadDataByDataSource();
- // 通过 AddTable 方法添加表格
- TableView tv = new TableView("table", "", 1, 0, 10, 7);
- fpSpread1.Sheets[0].AddTable(tv);
复制代码 |