Spread本身就有提供数据源绑定,可以给sheet绑定一个数据源,比如bindinglist,或者datatable
这里以一个bindinglist为例
绑定
- fpSpread1.Sheets[0].DataSource = MyData.GetProductList(30);
复制代码
增加和删除- private void 添加行ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- var list = (fpSpread1.Sheets[0].DataSource as BindingList<Product>);
- list.Add(new Product() { Id = list.Count });
- }
- private void 删除行ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- fpSpread1.ActiveSheet.RemoveRows(fpSpread1.ActiveSheet.ActiveRow.Index, 1);
- }
复制代码
|