//
var d= new DataTable()
//想加几个列就加几个列。
d.Columns.Add("a")
d.Columns.Add("b")
d.Columns.Add("c")
//相加几个行就加几个行
//每行可以满员,也可以个别字段没有值(比如这里的c)
var r = d.NewRow()
r["a"] = 1
r["b"] = 2
d.Rows.Add(r)
//数据的类型也可以随意整,不限制
var r2 = d.NewRow()
r2["a"] = "wakaka"
r2["c"] = 2
d.Rows.Add(r2)
//绑定上去
dataGridView1.DataSource = d
您好,要实现非常简单。需要四个按钮,一个datagridview控件。代码如下
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'添加行
Me.DataGridView1.Rows.Add()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
'添加列
Me.DataGridView1.Columns.Add("1", "on")
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'删除行
Me.DataGridView1.Rows.RemoveAt(0)
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
'删除列
Me.DataGridView1.Columns.RemoveAt(0)
End Sub
End Class
以上如有不清楚,您可以继续追问。希望对您有用!
DataGridViewTextBoxColumn colum = new DataGridViewTextBoxColumn()for (int a = 1 a <11 a++)
{
colum = new DataGridViewTextBoxColumn()
colum.Name = "第" + a.ToString() + "个"
dataGridView1.Columns.Add(colum)
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)