2012-10-14 52 views
0

我想在DataGrid中添加一個新行獲得新的行電網

添加新行

我要添加新的行格,然後我想集中注意力於電網。像這樣

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

如何做到這一點。

需要建議或代碼幫助

回答

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 

這不是太多的工作,但你並沒有給我們太多的與工作的。 。 。如果您可以多發佈一段代碼,或者更全面地解釋您想要做的事情,我們可以提供更有建設性的反饋。

希望幫助!