我想在datagrid中添加一个新行
添加新行
我想在网格中添加新行,然后我想要关注该网格。像这样
grid1.addrow()
grid.newrow.focus() 'I want to focus into new row
如何做到这一点。
需要建议或代码帮助
答案 0 :(得分:1)
这是一个非常粗糙的例子,因为我不知道你是如何填充你的dgv控件(当你说“Grid”时我假设你的意思是“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
这不太合适,但是你也没有给我们太多的帮助。 。 。如果您可以发布更多代码,或者更全面地解释您尝试做什么,我们可能能够提供更具建设性的反馈。
希望有所帮助!