SourceGrid是一个纯C#语言编写的网格控件,基于完全开放的原则.不受任何限制,包括限制使用权、拷贝、修改、合并、出版、分发等.实现了很多难以改决的问题.
先简单看一下如何绑定数据。
(1)声明行数和列数
Grid1.Redim(5, 5);
(2)创建表头
SourceGrid.Cells.ColumnHeader head1= new SourceGrid.Cells.ColumnHeader("head1");
SourceGrid.Cells.ColumnHeader head2 = new SourceGrid.Cells.ColumnHeader("head2");
SourceGrid.Cells.ColumnHeader head3 = new SourceGrid.Cells.ColumnHeader("head3");
SourceGrid.Cells.ColumnHeader head4 = new SourceGrid.Cells.ColumnHeader("head4");
SourceGrid.Cells.ColumnHeader head5 = new SourceGrid.Cells.ColumnHeader("head5");
Grid1[0, 0] = head1;
Grid1[0, 1] = head2;
Grid1[0, 2] = head3;
Grid1[0, 3] = head4;
Grid1[0, 4] = head5;
Grid1.AutoStretchColumnsToFitWidth = true;
Grid1.Columns[4].Width = 150;
(3)绑定数据
for (int i = 0; i < dt.Rows.Count; i++)
{
Grid1[i + 1, 0] = new SourceGrid.Cells.Cell(i+1);
Grid1[i + 1, 1] = new SourceGrid.Cells.Cell(dt.Rows[i]["head1"].ToString());
Grid1[i + 1, 2] = new SourceGrid.Cells.Cell(dt.Rows[i]["head2"].ToString());
Grid1[i + 1, 3] = new SourceGrid.Cells.Cell(dt.Rows[i]["head3"].ToString());
Grid1[i + 1, 4] = new SourceGrid.Cells.Cell(dt.Rows[i]["head4"].ToString());
}
完成。