我使用的是vs2010,控件为FarPoint spread8.0,我想从一个数据库中读取数据,然后显示在spread 表中。
这个窗体是通过点击一个按钮弹出的,
刚开始,仅仅在form_load中初始化一个表格行,代码如下,运行无问题。
private void test_Load(object sender, EventArgs e)
{
axfpSpread1.MaxCols = 10;
axfpSpread1.Row = 1;
axfpSpread1.Col = 1;
axfpSpread1.Text = "序号";
axfpSpread1.FontBold = true;
axfpSpread1.BackColor = Color.LightGray;
axfpSpread1.CellType = FPUSpreadADO.CellTypeConstants.CellTypeStaticText;
axfpSpread1.TypeVAlign = FPUSpreadADO.TypeVAlignConstants.TypeVAlignCenter;
axfpSpread1.TypeHAlign = FPUSpreadADO.TypeHAlignConstants.TypeHAlignCenter;
axfpSpread1.set_ColWidth(1, 5);
axfpSpread1.Col = 2;
axfpSpread1.Text = "内容1";
axfpSpread1.FontBold = true;
axfpSpread1.BackColor = Color.LightGray;
axfpSpread1.CellType = FPUSpreadADO.CellTypeConstants.CellTypeStaticText;
axfpSpread1.TypeVAlign = FPUSpreadADO.TypeVAlignConstants.TypeVAlignCenter;
axfpSpread1.TypeHAlign = FPUSpreadADO.TypeHAlignConstants.TypeHAlignCenter;
axfpSpread1.set_ColWidth(2, 10);
axfpSpread1.Col = 3;
axfpSpread1.Text = "内容2";
axfpSpread1.FontBold = true;
axfpSpread1.BackColor = Color.LightGray;
axfpSpread1.CellType = FPUSpreadADO.CellTypeConstants.CellTypeStaticText;
axfpSpread1.TypeVAlign = FPUSpreadADO.TypeVAlignConstants.TypeVAlignCenter;
axfpSpread1.TypeHAlign = FPUSpreadADO.TypeHAlignConstants.TypeHAlignCenter;
axfpSpread1.set_ColWidth(3, 12);
axfpSpread1.Col = 4;
axfpSpread1.Text = "内容3";
axfpSpread1.FontBold = true;
axfpSpread1.BackColor = Color.LightGray;
axfpSpread1.CellType = FPUSpreadADO.CellTypeConstants.CellTypeStaticText;
axfpSpread1.TypeVAlign = FPUSpreadADO.TypeVAlignConstants.TypeVAlignCenter;
axfpSpread1.TypeHAlign = FPUSpreadADO.TypeHAlignConstants.TypeHAlignCenter;
axfpSpread1.set_ColWidth(4, 7);
axfpSpread1.Col = 5;
axfpSpread1.Text = "内容4";
axfpSpread1.FontBold = true;
axfpSpread1.BackColor = Color.LightGray;
axfpSpread1.CellType = FPUSpreadADO.CellTypeConstants.CellTypeStaticText;
axfpSpread1.TypeVAlign = FPUSpreadADO.TypeVAlignConstants.TypeVAlignCenter;
axfpSpread1.TypeHAlign = FPUSpreadADO.TypeHAlignConstants.TypeHAlignCenter;
axfpSpread1.set_ColWidth(5, 7);
axfpSpread1.Col = 6;
axfpSpread1.Text = "内容5";
axfpSpread1.FontBold = true;
axfpSpread1.BackColor = Color.LightGray;
axfpSpread1.CellType = FPUSpreadADO.CellTypeConstants.CellTypeStaticText;
axfpSpread1.TypeVAlign = FPUSpreadADO.TypeVAlignConstants.TypeVAlignCenter;
axfpSpread1.TypeHAlign = FPUSpreadADO.TypeHAlignConstants.TypeHAlignCenter;
axfpSpread1.set_ColWidth(6, 10);
axfpSpread1.Col = 7;
axfpSpread1.Text = "内容6";
axfpSpread1.FontBold = true;
axfpSpread1.BackColor = Color.LightGray;
axfpSpread1.CellType = FPUSpreadADO.CellTypeConstants.CellTypeStaticText;
axfpSpread1.TypeVAlign = FPUSpreadADO.TypeVAlignConstants.TypeVAlignCenter;
axfpSpread1.TypeHAlign = FPUSpreadADO.TypeHAlignConstants.TypeHAlignCenter;
axfpSpread1.set_ColWidth(7, 12);
axfpSpread1.Col = 8;
axfpSpread1.Text = "内容7";
axfpSpread1.FontBold = true;
axfpSpread1.BackColor = Color.LightGray;
axfpSpread1.CellType = FPUSpreadADO.CellTypeConstants.CellTypeStaticText;
axfpSpread1.TypeVAlign = FPUSpreadADO.TypeVAlignConstants.TypeVAlignCenter;
axfpSpread1.TypeHAlign = FPUSpreadADO.TypeHAlignConstants.TypeHAlignCenter;
axfpSpread1.set_ColWidth(8, 6);
axfpSpread1.Col = 9;
axfpSpread1.Text = "内容8";
axfpSpread1.FontBold = true;
axfpSpread1.BackColor = Color.LightGray;
axfpSpread1.CellType = FPUSpreadADO.CellTypeConstants.CellTypeStaticText;
axfpSpread1.TypeVAlign = FPUSpreadADO.TypeVAlignConstants.TypeVAlignCenter;
axfpSpread1.TypeHAlign = FPUSpreadADO.TypeHAlignConstants.TypeHAlignCenter;
axfpSpread1.set_ColWidth(9, 6);
axfpSpread1.Col = 10;
axfpSpread1.Text = "内容9";
axfpSpread1.FontBold = true;
axfpSpread1.BackColor = Color.LightGray;
axfpSpread1.CellType = FPUSpreadADO.CellTypeConstants.CellTypeStaticText;
axfpSpread1.TypeVAlign = FPUSpreadADO.TypeVAlignConstants.TypeVAlignCenter;
axfpSpread1.TypeHAlign = FPUSpreadADO.TypeHAlignConstants.TypeHAlignCenter;
axfpSpread1.set_ColWidth(10, 7);
axfpSpread1.RowsFrozen = 1;
axfpSpread1.SetCellBorder(-1, -1, axfpSpread1.MaxCols, axfpSpread1.MaxRows, FPUSpreadADO.CellBorderIndexConstants.CellBorderIndexOutline, 0x00, FPUSpreadADO.CellBorderStyleConstants.CellBorderStyleSolid);
}
运行正常,然后在后面加上一段读取数据库数据的代码:
AccessDB myDb = new AccessDB();
DataSet ds = new DataSet();
string cmdstr = "select * from Tb_Telemetry where [项目]='" + SelProject + "' and [阶段]='" + SelPhase + "' and [代号]='" +
SelCode + "' order by [ID] asc";
ds = myDb.Getdataset(cmdstr);
axfpSpread1.MaxRows = ds.Tables[0].Rows.Count + 1;
将这段代码加到form_load中上段程序后面,调试时,点击按钮,弹出的spread表格是一个大空白,关闭这个窗体,再点击按钮,弹出的表格正常显示,请问,这是怎么回事? |
|