求助vb.net高手,如何在datagridview中添加行,添加列,删除行删除列。
您好,要实现非常简单。需要四个按钮,一个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
以上如有不清楚,您可以继续追问。希望对您有用!
row列标题可以修改吗?
可以的。
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
'添加列
Me.DataGridView1.Columns.Add("1", "这里输入你想要的标题就可以了额")
End Sub