您当前的位置看一看 -> 编程文档 -> .NET技术 -> VB.NET -> VB.NET技术资料-> 文章内容
栏目导航
热门文章
相关文章
动态增加和删除DataGrid中的行
作者:梓风 发布时间:2007-03-10

原帖及讨论:http://bbs.bc-cn.net/dispbbs.asp?BoardID=114&ID=98542

'*type为1表示要增加行 2为减去行
    Private Sub rowChange(ByVal type As Integer,byval GridType as DataGrid)
        Select Case type
            Case 1
                GridType.DataSource = CreateDataSource(Me.GridType.Items.Count + 1)
                GridType.DataBind()
            Case 2
                GridType.DataSource = CreateDataSource(Me.GridType.Items.Count - 1)
                GridType.DataBind()
        End Select
    End Sub

Function CreateDataSource(ByVal h As Integer) As ICollection
        Dim dt As New DataTable
        Dim dr As DataRow
        Dim i As Integer
        For i = 0 To h - 1
            dr = dt.NewRow()
            dt.Rows.Add(dr)
        Next i
        Dim dv As New DataView(dt)
        Return dv
End Function