在网格视图中复制选定的行

时间:2011-10-23 05:05:15

标签: vb.net visual-studio

使用VB.Net

用户在GridView列中输入值

每一行都有复选框,如果选中复选框,则用户想要将一行复制到另一行。

例如

用户输入前2行的值,再次用户不想输入值,用户希望将前2行复制到下2行。

If gridview1.column(0).checkbox1.checked = True then
'Copy that selected row to next row. (Here i have to create a table to copy the new rows or i can copy directly gridrow values without creating a tables)

Gridview1

复选框ID名称

check/uncheck 001 Raja
check/uncheck 002 Ramu
check/uncheck 003 Vijay
.....

如果我检查最后2行意味着它应该自动添加,ID号也应该增加

预期输出

check/uncheck 001 Raja
check/uncheck 002 Ramu
check/uncheck 003 Vijay
check/uncheck 004 Ramu
check/uncheck 005 Vijay
.....

如何做到这一点。给我一个想法

需要VB.Net代码帮助

1 个答案:

答案 0 :(得分:0)

从您之前版本的此问题中编辑我的回答。哪个应该有效。我添加了代码以增加添加行的ID号。

      For Each m_row As System.Windows.Forms.DataGridViewRow In Me.grvLIst.Rows
        'Create new row to hold duplicated values
        Dim NewRow As New DataGridViewRow
        'make row have same columns as other rows in the datagrid
        NewRow.CreateCells(Me.grvLIst)
        'loop thru values in the row being copied and place values in new row
        For i As Integer = 0 To m_row.Cells.Count - 1
            NewRow.Cells(i).Value = m_row.Cells(i).Value
        Next

        'This will increase the id number by 1 based on the last rows id number
        NewRow.Cells(1).Value = Me.grvLIst.Rows(Me.grvLIst.RowCount - 1).Cells(1).Value + 1
        'Add newly create row to gridview

        Me.grvLIst.Rows.Add(NewRow)

    Next