0

我想在数据网格中添加一个新行

添加新行

我想在网格中添加新行,然后我想关注那个网格。像这样

grid1.addrow()
grid.newrow.focus() 'I want to focus into new row

这该怎么做。

需要建议或代码帮助

4

1 回答 1

1

这是一个非常粗略的示例,因为我不知道您如何或使用什么来填充 dgv 控件(当您说“网格”时,我假设您的意思是“DataGridView”):

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    Dim dgv As DataGridView = Me.DataGridView1
    Dim newRow As DataGridViewRow
    Dim rowData() As String = {"John", "Doe"}

    'Add a first row, just so we can see that this works:
    newRow = dgv.Rows(dgv.Rows.Add(rowData))
    newRow.Selected = False

    ' Now create some random data for the next row:
    rowData(0) = "Mary"
    rowData(1) = "Smith"

    ' Add the next row:
    newRow = dgv.Rows(dgv.Rows.Add(rowData))

    ' Set the status of the first cell (element zero in the array of cells
    ' to Selected = true:
    newRow.Cells(0).Selected = True

    'If you want a reference to the active cell:
    Dim cell As DataGridViewCell = newRow.Cells(0)

End Sub

这没什么好合作的,但你也没有给我们太多的合作机会。. . 如果您可以发布更多代码,或者更全面地解释您正在尝试做什么,我们也许能够提供更具建设性的反馈。

希望有帮助!

于 2012-10-14T14:29:18.363 回答